473,372 Members | 1,015 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,372 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 9227
"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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.