473,386 Members | 1,773 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,386 software developers and data experts.

Resizing Background Image

How doy you resize the background image to fill a form
when the form is resized?
Nov 20 '05 #1
2 8742
* "Nathan" <an*******@discussions.microsoft.com> scripsit:
How doy you resize the background image to fill a form
when the form is resized?


Add this to the form's constructor:

\\\
SetStyle(ControlStyles.ResizeRedraw, True)
UpdateStyles()
///

Then you can draw the image in the form's 'Paint' event handler.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Nathan,
In addition to Herfried's suggestion.

I would consider creating a new Bitmap in the Resize event to the same size
as the Client Rectangle. In the Resize event use the Graphics.Draw* methods
to draw your background onto this Bitmap. I would then simply set the
BackgroundImage property of the form in the Resize event letting the Form do
all the work.

This obviously works best if you have a simply background like a gradient
brush shown. For more a more complex background I would consider staying
with the Paint or PaintBackground events & the method Herfried showed.

Something like:

Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)

If Not Me.BackgroundImage Is Nothing Then
Me.BackgroundImage.Dispose()
Me.BackgroundImage = Nothing
End If
Dim image As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
Dim gr As Graphics = Graphics.FromImage(image)
Dim rect As New Rectangle(New Point(0, 0), Me.ClientSize)

Dim brush As New LinearGradientBrush(rect, _
Color.RosyBrown, ControlPaint.LightLight(Color.RosyBrown), _
LinearGradientMode.Vertical)
brush.SetBlendTriangularShape(0.33)
gr.FillRectangle(brush, rect)
gr.Dispose()

Me.BackgroundImage = image
End Sub

The normal PaintBackground event handler will use the BackgroundImage image
to tile on the background, seeing as this image is the size of the client
area there is no stretching or tiling involved.

Hope this helps
Jay
"Nathan" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
How doy you resize the background image to fill a form
when the form is resized?

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Scott Hatton | last post by:
I have a table like this
13
by: Jon Yeager | last post by:
I need to display a bunch of pictures that are all of various dimensions into a fixed dimension space, like MSN Messenger does with its user photos in the chat windows. Forcing image dimensions...
1
by: Ron Vecchi | last post by:
I am using asp.net to upload an image and then perform resizing on it and saving the different sizes to file. The resized images were coming up and being displayed in the bowser fine but the image...
0
by: Oleg Ogurok | last post by:
Hi all, I'm having this problem. I have a 50x50 GIF image with a transparent background. I'm trying to resize it to 25x25 using GDI+ capabilities. With Windows Forms' Image control, the image...
14
by: Seige | last post by:
Ever had headache when you can't resize the background width using CSS: body{ background: url(/images/bg.jpg) ; background-width: 800px; } It won't work, would it? Of course not, it's not even...
6
by: tomasio | last post by:
Dear NG, years have passed and I am still more designer than programmer. I build a new version of my website which has a few nasty bugs, especially on my startpage: Resizing text brakes the...
5
by: drum118 | last post by:
Trying to resize a photo to use it as a background and it fails under part of the css <img src="subway/IMG_0730.JPG" width="3264" height="2448" alt="" /> I have try and the photo does not...
0
by: whairs01 | last post by:
Could someone help me and telling me how to get my 3 column web page to resize correctly in IE7. When trying to reside my my web page I can only get it to resize to a point before the 2 and 3...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.