473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
8 9237
"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
"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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Theodore A. Jencks | last post by:
Hi all, I posted a question about a side navigation bar earlier where I was encountering this problem. I thought I'd repost the question in a more general format because I'm not sure people...
3
by: Greg Heilers | last post by:
Hello everyone... If one has a <div> that is completely filled with a background-image; how does one style it so that the image *continues* to fill the <div> top-to-bottom, left-to-right; if...
1
by: Aku | last post by:
Hello, In my C# app I put a background image (.jpg) via the Properties attributes. The image appears several times, tiled - so if you resized the dialog, more will appear! This is not what I...
0
by: Matt | last post by:
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...
2
by: Patrick | last post by:
Hi All, I am trying more and more to incorporate CSS into my work here. I have currently been playing around with fluid design and tableless layout. Currently I am trying to make a background...
8
by: paul.denlinger | last post by:
Hi-- Things have gone well for me on this page design, but when I added a background image, it pushed everything down and messed up my page layout. Before I added the navigation background...
1
by: swc76801 | last post by:
I desperately need help. My understanding of CSS is non-existent. I have a store http://astore.amazon.com/texasheat-20 with Amazon.com. According to the information from Amazon.com "Write your own...
0
by: summiyashaheen | last post by:
i want the button to resize on a window form in vb.net when the window is maximized or resotered. there is an image as background. buttons are placed according to the image parts. when the window is...
3
by: ramesh1210 | last post by:
Hi all, Actually my requirement is to place an image in the text box and it should stand over the data in the text box. And i made it as ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.