Question Paint on parent form

Pirahnaplant

Well-known member
Joined
Mar 29, 2009
Messages
75
Programming Experience
3-5
I need for my control to paint on the its parent form. This is the code I have been trying, but the paint event never gets activated.

VB.NET:
    Private WithEvents contForm As Form = Me.ParentForm

    Private Sub contForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles contForm.Paint
        'code goes here
    End Sub
 
In your control are you telling the parentform to repaint? If not the sub will not fire until such time.
 
I figured out what the problem was, contForm was being initialized before the parent form was, so it was 'Nothing'. This is the code I used to fix it:

VB.NET:
    Private WithEvents contForm As Form

    Protected Overrides Sub InitLayout()
        contForm = Me.ParentForm
        MyBase.InitLayout()
    End Sub

    Private Sub contForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles contForm.Paint
        'code goes here
    End Sub
 
Back
Top