By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

Adding a background image that resizes along with the MDI form.

P: n/a
I've been searching around for a simple way to display a background
image in my MDI form's client area.
I want to be able to load the image from file on start up
and have it resize as the MDI form is resized.

It's the resizing part that I am having trouble with.

I've seen a few old posts that point in the right direction but
nothing simple.
I wondered if they has been any new ideas I have missed.

Working with an MDI child form is easy and the following code works a
treat.

Public Class Form2
Inherits System.Windows.Forms.Form

Private newImage As Image =
Image.FromFile("D:\Pics\Background.bmp")
Private Sub Form2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

' Create a rectangle the size of the child form.
Dim destRect As New Rectangle(1, 1, Me.ClientSize.Width,
Me.ClientSize.Height)

' Draw image to screen.
e.Graphics.DrawImage(newImage, destRect)
End Sub
End Class

Is there anything as simple for the MDI form?
Failing that, anything at all that works?

Thank you in advance.

Matt
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"Matt" <mt*****@gladstonemrm.com> schrieb:
I've been searching around for a simple way to display a background
image in my MDI form's client area.
I want to be able to load the image from file on start up
and have it resize as the MDI form is resized.
[...]
Is there anything as simple for the MDI form?
Failing that, anything at all that works?


Customizing the MDI frame background
<URL:http://www.bobpowell.net/mdiback.htm>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2

P: n/a
"Matt" <mt*****@gladstonemrm.com> schrieb:
I've been searching around for a simple way to display a background
image in my MDI form's client area.
I want to be able to load the image from file on start up
and have it resize as the MDI form is resized.
[...]
Is there anything as simple for the MDI form?
Failing that, anything at all that works?


Customizing the MDI frame background
<URL:http://www.bobpowell.net/mdiback.htm>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #3

P: n/a
Hi Matt

The general technique is highlighted very well at Bob Powell's site:

http://www.bobpowell.net/mdiback.htm

I've written the code that follows, and it works, but there is horrible
flashing when you resize - the background of the MdiClient control is painted
first, followed by the drawing of the Image on top. I can't see a way to
suppress the drawing of the background though - any ideas out there?

Hope it's some help anyway...

Nigel Armstrong

Code (Form called Form1.vb, with IsMdiContainer set to true...) :
Dim b As Bitmap

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' probably better to load this from a resource file, but this works for a
demo!
b = New Bitmap("C:\test.jpg")
For Each c As Control In Me.Controls
' Find the MdiClient control
If TypeOf c Is MdiClient Then
' Add in handlers for resize and paint
AddHandler c.Paint, AddressOf MyPaint
AddHandler c.SizeChanged, AddressOf MySizeChanged
End If
Next
End Sub

' Here are the handlers
Private Sub MyPaint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawImage(b, 0, 0, Me.ClientSize.Width,
Me.ClientSize.Height)
End Sub

Private Sub MySizeChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.Invalidate()
End Sub
"Matt" wrote:
I've been searching around for a simple way to display a background
image in my MDI form's client area.
I want to be able to load the image from file on start up
and have it resize as the MDI form is resized.

It's the resizing part that I am having trouble with.

I've seen a few old posts that point in the right direction but
nothing simple.
I wondered if they has been any new ideas I have missed.

Working with an MDI child form is easy and the following code works a
treat.

Public Class Form2
Inherits System.Windows.Forms.Form

Private newImage As Image =
Image.FromFile("D:\Pics\Background.bmp")
Private Sub Form2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

' Create a rectangle the size of the child form.
Dim destRect As New Rectangle(1, 1, Me.ClientSize.Width,
Me.ClientSize.Height)

' Draw image to screen.
e.Graphics.DrawImage(newImage, destRect)
End Sub
End Class

Is there anything as simple for the MDI form?
Failing that, anything at all that works?

Thank you in advance.

Matt

Nov 21 '05 #4

P: n/a
Hi Matt

The general technique is highlighted very well at Bob Powell's site:

http://www.bobpowell.net/mdiback.htm

I've written the code that follows, and it works, but there is horrible
flashing when you resize - the background of the MdiClient control is painted
first, followed by the drawing of the Image on top. I can't see a way to
suppress the drawing of the background though - any ideas out there?

Hope it's some help anyway...

Nigel Armstrong

Code (Form called Form1.vb, with IsMdiContainer set to true...) :
Dim b As Bitmap

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' probably better to load this from a resource file, but this works for a
demo!
b = New Bitmap("C:\test.jpg")
For Each c As Control In Me.Controls
' Find the MdiClient control
If TypeOf c Is MdiClient Then
' Add in handlers for resize and paint
AddHandler c.Paint, AddressOf MyPaint
AddHandler c.SizeChanged, AddressOf MySizeChanged
End If
Next
End Sub

' Here are the handlers
Private Sub MyPaint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.DrawImage(b, 0, 0, Me.ClientSize.Width,
Me.ClientSize.Height)
End Sub

Private Sub MySizeChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.Invalidate()
End Sub
"Matt" wrote:
I've been searching around for a simple way to display a background
image in my MDI form's client area.
I want to be able to load the image from file on start up
and have it resize as the MDI form is resized.

It's the resizing part that I am having trouble with.

I've seen a few old posts that point in the right direction but
nothing simple.
I wondered if they has been any new ideas I have missed.

Working with an MDI child form is easy and the following code works a
treat.

Public Class Form2
Inherits System.Windows.Forms.Form

Private newImage As Image =
Image.FromFile("D:\Pics\Background.bmp")
Private Sub Form2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

' Create a rectangle the size of the child form.
Dim destRect As New Rectangle(1, 1, Me.ClientSize.Width,
Me.ClientSize.Height)

' Draw image to screen.
e.Graphics.DrawImage(newImage, destRect)
End Sub
End Class

Is there anything as simple for the MDI form?
Failing that, anything at all that works?

Thank you in advance.

Matt

Nov 21 '05 #5

P: n/a
Thanks guys,

I'm sure it will do the job.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #6

P: n/a
Thanks guys,

I'm sure it will do the job.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #7

P: n/a
Works really well Nigel, thanks.

The flashing is odd though but not a big deal.
If time allows I'll mess about with it.
Let me know if you come up with anything.

Thanks again.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #8

P: n/a
Works really well Nigel, thanks.

The flashing is odd though but not a big deal.
If time allows I'll mess about with it.
Let me know if you come up with anything.

Thanks again.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.