469,343 Members | 5,388 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

How To Create A Gradient Background

How does one create a gradient background for a form?
Nov 21 '05 #1
6 20690
Override OnPaintBackground and see the LinearGradientBrush help details.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"HenryC" <he***@tste.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
How does one create a gradient background for a form?

Nov 21 '05 #2
Thanks,
I am new to VB and have already read quite a bit without getting it right.
Some code snippet would be nice.
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eE**************@TK2MSFTNGP15.phx.gbl...
Override OnPaintBackground and see the LinearGradientBrush help details.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"HenryC" <he***@tste.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
How does one create a gradient background for a form?


Nov 21 '05 #3
Stick this behind the form

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

MyBase.OnPaint(e)

Dim baseBackground As System.Drawing.Drawing2D.LinearGradientBrush

baseBackground = New LinearGradientBrush(New Point(0, 0), _

New Point(ClientSize.Width, 0), _

Color.Blue, _

Color.Red)

e.Graphics.FillRectangle(baseBackground, ClientRectangle)

End Sub

"HenryC" <he***@tste.com> wrote in message
news:uW**************@TK2MSFTNGP14.phx.gbl...
Thanks,
I am new to VB and have already read quite a bit without getting it right.
Some code snippet would be nice.
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eE**************@TK2MSFTNGP15.phx.gbl...
Override OnPaintBackground and see the LinearGradientBrush help details.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"HenryC" <he***@tste.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> How does one create a gradient background for a form?
>
>



Nov 21 '05 #4
Thanks John

"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:4v******************@newsfe6-gui.ntli.net...
Stick this behind the form

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

MyBase.OnPaint(e)

Dim baseBackground As System.Drawing.Drawing2D.LinearGradientBrush

baseBackground = New LinearGradientBrush(New Point(0, 0), _

New Point(ClientSize.Width, 0), _

Color.Blue, _

Color.Red)

e.Graphics.FillRectangle(baseBackground, ClientRectangle)

End Sub

"HenryC" <he***@tste.com> wrote in message
news:uW**************@TK2MSFTNGP14.phx.gbl...
Thanks,
I am new to VB and have already read quite a bit without getting it right. Some code snippet would be nice.
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eE**************@TK2MSFTNGP15.phx.gbl...
Override OnPaintBackground and see the LinearGradientBrush help details.
--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"HenryC" <he***@tste.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> How does one create a gradient background for a form?
>
>



Nov 21 '05 #5
Thanks Bob,
I went to your site and got the code snippet I needed.

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eE**************@TK2MSFTNGP15.phx.gbl...
Override OnPaintBackground and see the LinearGradientBrush help details.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"HenryC" <he***@tste.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
How does one create a gradient background for a form?


Nov 21 '05 #6
Henry,
In addition to the other comments.

I've set the BackgroundImage of the from to an image that was painted with a
gradient brush, something like:

Protected Overrides Sub OnLayout(ByVal e As LayoutEventArgs)
MyBase.OnLayout(e)

If Not Me.BackgroundImage Is Nothing Then
If Size.op_Equality(Me.BackgroundImage.Size, Me.ClientSize) Then
Exit Sub
End If
Me.BackgroundImage.Dispose()
Me.BackgroundImage = Nothing
End If

Dim rect As New Rectangle(New Point(0, 0), Me.ClientSize)
Dim image As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
Dim gr As Graphics = Graphics.FromImage(image)

Dim brush As New LinearGradientBrush(rect,
ControlPaint.LightLight(Me.BackColor), Me.BackColor,
LinearGradientMode.Vertical)
brush.SetBlendTriangularShape(2 / 3)

gr.FillRectangle(brush, rect)
gr.Dispose()
brush.Dispose()

Me.BackgroundImage = image
End Sub

Hope this helps
Jay

"HenryC" <he***@tste.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
| How does one create a gradient background for a form?
|
|
Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Wayne Wengert | last post: by
reply views Thread by David Gouge | last post: by
6 posts views Thread by moondaddy | last post: by
9 posts views Thread by Eric Lindsay | last post: by
5 posts views Thread by Bob Altman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.