none
What's going on behind Paint OnSub?

    Question

  • Hello everyone,

    This elementary VB program with a Form and just one TextBox:

    Public Class Form1
        Protected Overrides Sub OnPaint(e As PaintEventArgs)
            MyBase.OnPaint(e)
            TextBox1.AppendText("Booo" & vbCrLf)
            e.Dispose()
        End Sub
    End Class 

    continues over time to output text in the Textbox (let it run 3-5 minutes) like this:

    I was the impression that the OnPaint Sub was run only one time at the beginning of execution. Could anybody explain? 

    Big Buzzard.


    Philippe de Marchin

    Monday, March 27, 2017 12:37 AM

Answers

  • Hi

    Because you are causing the textbox to change, that causes the Paint event to fire and you are in a loop then.


    Regards Les, Livingston, Scotland

    • Proposed as answer by Cor Ligthert Monday, March 27, 2017 7:29 AM
    • Marked as answer by BigBuzzard Monday, March 27, 2017 6:47 PM
    Monday, March 27, 2017 12:39 AM
  • I was the impression that the OnPaint Sub was run only one time at the beginning of execution.

    No.  The event fires whenever the form needs to be re-displayed.

    • Proposed as answer by Cor Ligthert Monday, March 27, 2017 7:29 AM
    • Marked as answer by BigBuzzard Monday, March 27, 2017 6:47 PM
    Monday, March 27, 2017 2:09 AM
    • Marked as answer by BigBuzzard Monday, March 27, 2017 6:47 PM
    Monday, March 27, 2017 11:50 AM

All replies