473,756 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\Backgr ound.bmp")
Private Sub Form2_Paint(ByV al sender As Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint

' Create a rectangle the size of the child form.
Dim destRect As New Rectangle(1, 1, Me.ClientSize.W idth,
Me.ClientSize.H eight)

' Draw image to screen.
e.Graphics.Draw Image(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 9272
"Matt" <mt*****@gladst onemrm.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.n et/mdiback.htm>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2
"Matt" <mt*****@gladst onemrm.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.n et/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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) 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.PaintEven tArgs)
e.Graphics.Draw Image(b, 0, 0, Me.ClientSize.W idth,
Me.ClientSize.H eight)
End Sub

Private Sub MySizeChanged(B yVal sender As Object, ByVal e As
System.EventArg s)
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\Backgr ound.bmp")
Private Sub Form2_Paint(ByV al sender As Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint

' Create a rectangle the size of the child form.
Dim destRect As New Rectangle(1, 1, Me.ClientSize.W idth,
Me.ClientSize.H eight)

' Draw image to screen.
e.Graphics.Draw Image(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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) 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.PaintEven tArgs)
e.Graphics.Draw Image(b, 0, 0, Me.ClientSize.W idth,
Me.ClientSize.H eight)
End Sub

Private Sub MySizeChanged(B yVal sender As Object, ByVal e As
System.EventArg s)
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\Backgr ound.bmp")
Private Sub Form2_Paint(ByV al sender As Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint

' Create a rectangle the size of the child form.
Dim destRect As New Rectangle(1, 1, Me.ClientSize.W idth,
Me.ClientSize.H eight)

' Draw image to screen.
e.Graphics.Draw Image(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
6457
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 quite understood what I was asking in my last post. Here is what I'd like to do: 1. Have a div tag that's soul purpose is to display a repeating background image in the y-axis. 2. The div tag should also have a fixed width.
3
4979
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 the viewer adjusts the font-size on his browser? I have everything sized in em's, so that the actual <div> "box" resizes along with the text, but the background-image will not resize if the text is "zoomed". I can not find anything pertaining
1
2886
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 wanted; I meant to get one image, and it should be stretched to full window size and automaticallly resize along with the form. Can you advise me please.
0
391
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 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.
2
3080
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 image show up in a div that is designated by an id. The image is not appearing and after doing some googling I'm still a bit lost. Is it possible to display a background image in a div ID? Can someone school me a bit on this? I have supplied a...
8
3903
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 image, here is the CSS code: body { font-family:Verdana, Arial, Helvetica, sans-serif;
1
19671
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 overriding CSS to customize your aStore." Their setup page is divided into two sections. On the right they show the existing CSS. On the left there is a box where you can add the new code. They have tabs for "Global", "Category Page", "Detail Page",...
0
942
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 maximized, image portion expands but the buttin size is fixed. how to fix the size of the button according to the image portion.......
3
2875
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 ------------------------------------------------------------------------------------------ <html> <head> <style> .formlabel
0
9462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9287
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9886
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9857
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9722
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.