I
Ivan Weiss
Hey all, I am using the following code to attempt to draw an image on
the MdiClient Area thanks to some help from another post.
However, the line If m_MDIClient.Width > 0 And m_MDIClient.Height > 0
Then is throwing an exception saying m_MDIClient is a null reference.
I have the following variables at the top of the form:
Private m_MDIClient As MdiClient
Private m_OriginalBackgroundImage As Image
Private m_IgnoreSetBackgroundImage As Boolean
Here is the code in my form constructor:
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is MdiClient Then
m_MDIClient = ctl
m_MDIClient.BackColor = Me.BackColor
Exit For
End If
Next
In the mdi load I have:
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Than I have the following functions (updatebackground throws the
exception)
Private Sub mdiMain_BackgroundImageChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.BackgroundImageChanged
If Not m_IgnoreSetBackgroundImage Then
m_OriginalBackgroundImage = Me.BackgroundImage
UpdateBackGround()
End If
End Sub
Private Sub mdiMain_Resize(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Resize
If Not (m_MDIClient Is Nothing) Then UpdateBackGround()
End Sub
Private Sub UpdateBackGround()
If Not (m_OriginalBackgroundImage Is Nothing) Then
If m_MDIClient.Width > 0 And m_MDIClient.Height > 0 Then
Dim b As Bitmap = New Bitmap(m_MDIClient.Width,
m_MDIClient.Height)
Dim g As Graphics = Me.CreateGraphics.FromImage(b)
g.Clear(Me.BackColor)
g.DrawImage(m_OriginalBackgroundImage, New
Point((m_MDIClient.Width - m_OriginalBackgroundImage.Width) / 2,
(m_MDIClient.Height - m_OriginalBackgroundImage.Height) / 2))
m_IgnoreSetBackgroundImage = True
Me.BackgroundImage = b
m_IgnoreSetBackgroundImage = False
End If
End If
End Sub
If anyone has any ideas that would be great, thanks!
-Ivan
the MdiClient Area thanks to some help from another post.
However, the line If m_MDIClient.Width > 0 And m_MDIClient.Height > 0
Then is throwing an exception saying m_MDIClient is a null reference.
I have the following variables at the top of the form:
Private m_MDIClient As MdiClient
Private m_OriginalBackgroundImage As Image
Private m_IgnoreSetBackgroundImage As Boolean
Here is the code in my form constructor:
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is MdiClient Then
m_MDIClient = ctl
m_MDIClient.BackColor = Me.BackColor
Exit For
End If
Next
In the mdi load I have:
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Than I have the following functions (updatebackground throws the
exception)
Private Sub mdiMain_BackgroundImageChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.BackgroundImageChanged
If Not m_IgnoreSetBackgroundImage Then
m_OriginalBackgroundImage = Me.BackgroundImage
UpdateBackGround()
End If
End Sub
Private Sub mdiMain_Resize(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Resize
If Not (m_MDIClient Is Nothing) Then UpdateBackGround()
End Sub
Private Sub UpdateBackGround()
If Not (m_OriginalBackgroundImage Is Nothing) Then
If m_MDIClient.Width > 0 And m_MDIClient.Height > 0 Then
Dim b As Bitmap = New Bitmap(m_MDIClient.Width,
m_MDIClient.Height)
Dim g As Graphics = Me.CreateGraphics.FromImage(b)
g.Clear(Me.BackColor)
g.DrawImage(m_OriginalBackgroundImage, New
Point((m_MDIClient.Width - m_OriginalBackgroundImage.Width) / 2,
(m_MDIClient.Height - m_OriginalBackgroundImage.Height) / 2))
m_IgnoreSetBackgroundImage = True
Me.BackgroundImage = b
m_IgnoreSetBackgroundImage = False
End If
End If
End Sub
If anyone has any ideas that would be great, thanks!
-Ivan