Question Paint event

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I have a program with 2 forms where form1 would have a line form2.show() and in form2 would have a form size change line. but for some reason the paint codes doesnt fire after the size change. I have no idea why.

all the buttons that is inside form2 get painted, just not the form paint event. right now i set a timer in the load event for the size change. the form paint event would fire when the size change isnt in the load.

do you know why?

VB.NET:
    Private Sub Form2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

'Paint Codes

    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
             Me.Size = New Point(270, 25)

    End Sub
 
The form has a Resize event that you can use to detect when resizing occurs and call Invalidate, which causes the form to repaint.
 
Paint

Thats what weird about it. No matter what i do. If i do a resize during the Load event, it just wont paint. I Invalidate, update, refresh. Nothing works. Only works if i resize after its loaded.
 
Why would you set the Size during the Load event? If you know the size to be able to hard-code it then why would you not just set the Size in the designer? You'd only do that if you were using variables, not literals.

Also, the form is not visible when the Load event handler is executed so changing the Size in the Load event handler won't cause a repaint because there's nothing to paint. The form isn't painted for the first time until AFTER the Load event handler completes.

Can you show us your actual code and explain exactly what you expect to happen that doesn't?
 
Back
Top