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

How To Create A Gradient Background

How does one create a gradient background for a form?
Nov 21 '05 #1
6 21641
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert W. | last post by:
In my Winforms app I'm trying to get an image's background to appear transparent on a form that has a gradient background. So I added a PictureBox and then attempted to add a custom paint command...
4
by: Wayne Wengert | last post by:
I'm looking for information or samples of how to display a gradient background color for an ASP.NET web page. I want to be able to set a start and end color (e.g. Light Orange to White) and have...
0
by: Don | last post by:
I'm making a custom control that has a multiline textbox on it. I want to make the textbox have a gradient background. On my custom control's Paint event I call a routine that draws a gradient on...
0
by: David Gouge | last post by:
Hi All, appreciate that this is more gdi+ than c# but always seem to get good answers here, so here goes... In a nutshell, all i want to do is add a gradient background to a ListView. I have...
1
by: madladuk | last post by:
Hi all. Does anyone have any example of how to do a gradient background whilst moving over graphics and text like the Microsoft web site. On the MS site when you select an area a window popup...
6
by: moondaddy | last post by:
I want to fill the entire background of a page with a gradient. As a test, I first filled with a solid color like this: <body style="background-color: #ccffff;" > and the entire page was this...
9
by: Eric Lindsay | last post by:
How do you provide a consistent gradient fill as a background in a liquid layout? If I make a gradient fill image say 1000 pixels wide (and repeat it down the page) to suit a typical computer...
1
by: Bryon | last post by:
My current code paints a rectangular area at the top (under the menu and tool strip) and bottom (top of the status strip) of the main form with a linear gradient. The problem is that when the form...
5
by: Bob Altman | last post by:
Hi all, Here's another rank beginner question. What is the standard way to fill a client-side table cell with a horizontal gradient background? TIA - Bob
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...
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
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.