Drawing an Image on MDI Form

badbee

New member
Joined
Feb 21, 2006
Messages
2
Programming Experience
1-3
I am trying to draw an image on MDI Form.
I am using the following code in the Paint Event of the form:
For Each ctl In Me.Controls
If TypeOf (ctl) Is MdiClient Then

ctl.CreateGraphics.DrawImage(Image.FromFile("C:\Logo.bmp"), New Point(10, 10))
End If
Next




Now, i am having a problem. The problem is that when the form is loaded at the first time, the image is not drawn. But, whenever the paint event occurs after the form is visible, the graphic is drawn.

Any ideas ?
 
If you're drawing on the MdiClient then it's probably better that you use its Paint event rather than the form's:
VB.NET:
    Private WithEvents client As MdiClient

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each ctl As Control In Me.Controls
            If TypeOf ctl Is MdiClient Then
                Me.client = DirectCast(ctl, MdiClient)
                Exit For
            End If
        Next ctl
    End Sub

    Private Sub client_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles client.Paint
        'Paint on the MdiClient here.
    End Sub
By declaring your own variable WithEvents you are able to handle its events just like those of controls added in the designer, so you can use the IDE to generate the event handler for you.
 
Back
Top