473,728 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Create A Gradient Background

How does one create a gradient background for a form?
Nov 21 '05 #1
6 21687
Override OnPaintBackgrou nd and see the LinearGradientB rush 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******** ********@TK2MSF TNGP12.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@_spamkille r_bobpowell.net > wrote in message
news:eE******** ******@TK2MSFTN GP15.phx.gbl...
Override OnPaintBackgrou nd and see the LinearGradientB rush 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******** ********@TK2MSF TNGP12.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.Linea rGradientBrush

baseBackground = New LinearGradientB rush(New Point(0, 0), _

New Point(ClientSiz e.Width, 0), _

Color.Blue, _

Color.Red)

e.Graphics.Fill Rectangle(baseB ackground, ClientRectangle )

End Sub

"HenryC" <he***@tste.com > wrote in message
news:uW******** ******@TK2MSFTN GP14.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@_spamkille r_bobpowell.net > wrote in message
news:eE******** ******@TK2MSFTN GP15.phx.gbl...
Override OnPaintBackgrou nd and see the LinearGradientB rush 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******** ********@TK2MSF TNGP12.phx.gbl. ..
> How does one create a gradient background for a form?
>
>



Nov 21 '05 #4
Thanks John

"JohnFol" <Ou************ @WibbleObbble.C om> wrote in message
news:4v******** **********@news fe6-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.Linea rGradientBrush

baseBackground = New LinearGradientB rush(New Point(0, 0), _

New Point(ClientSiz e.Width, 0), _

Color.Blue, _

Color.Red)

e.Graphics.Fill Rectangle(baseB ackground, ClientRectangle )

End Sub

"HenryC" <he***@tste.com > wrote in message
news:uW******** ******@TK2MSFTN GP14.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@_spamkille r_bobpowell.net > wrote in message
news:eE******** ******@TK2MSFTN GP15.phx.gbl...
Override OnPaintBackgrou nd and see the LinearGradientB rush 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******** ********@TK2MSF TNGP12.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@_spamkille r_bobpowell.net > wrote in message
news:eE******** ******@TK2MSFTN GP15.phx.gbl...
Override OnPaintBackgrou nd and see the LinearGradientB rush 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******** ********@TK2MSF TNGP12.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.BackgroundIm age Is Nothing Then
If Size.op_Equalit y(Me.Background Image.Size, Me.ClientSize) Then
Exit Sub
End If
Me.BackgroundIm age.Dispose()
Me.BackgroundIm age = Nothing
End If

Dim rect As New Rectangle(New Point(0, 0), Me.ClientSize)
Dim image As New Bitmap(Me.Clien tSize.Width, Me.ClientSize.H eight)
Dim gr As Graphics = Graphics.FromIm age(image)

Dim brush As New LinearGradientB rush(rect,
ControlPaint.Li ghtLight(Me.Bac kColor), Me.BackColor,
LinearGradientM ode.Vertical)
brush.SetBlendT riangularShape( 2 / 3)

gr.FillRectangl e(brush, rect)
gr.Dispose()
brush.Dispose()

Me.BackgroundIm age = image
End Sub

Hope this helps
Jay

"HenryC" <he***@tste.com > wrote in message
news:%2******** ********@TK2MSF TNGP12.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
4119
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 for the PictureBox. But it's not working. Here's the code I've written: public void InitializeLinearGradients() { this.Paint += new PaintEventHandler(PaintClient); this.SizeChanged += new EventHandler(SizeClient); pictureLogo.Paint += new...
4
10074
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 the page rendered with that gradient background from left to right. Using google I found several examples but they all appeared to apply only to Windows Forms Wayne
0
4445
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 the textbox's background, but the gradient starts appearing at the bottom of the textbox after the last line of text. It's almost as if VB draws the gradient on the entire textbox, then blanks out the part of the textbox that actually displays...
0
3038
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 gotten so far by: Adding the following to the constructor: this.SetStyle(ControlStyles.UserPaint, true);
1
1660
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 and as you hover over the sections it fill in a nice gradient background, any assistance? Thanks
6
6167
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 color. next I replaced that with a gradient style like this: <body style="filter:
9
8143
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 display, then only a small portion of the gradient will show if the viewpoint is a smaller PDA or phone display. On the other hand, if viewed full screen on a 1920 pixel wide display, I would run out of gradient on one or both sides of the page....
1
1862
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 is resized or maximized for that matter, the form still displays the last areas that were painted with gradient. Basically the form does not erase the last graphics that were painted to the form and just paints over it with the new. My code is...
5
3448
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
8904
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
8759
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
9424
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9277
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
9198
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
8133
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.