472,378 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 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 21377
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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.