black->white gradient; left to right

bwells

Well-known member
Joined
Feb 25, 2003
Messages
84
How can I draw a gradient, in a panel (bitmap?) that goes from black to white from left to right? I can create the bitmap easliy enough, but I thought there might be an easy way to draw such a gradient with GDI+ so I can resize it as needed.

thanks
Bryan
 
Code:
    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Dim b As Brush

        b = New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Panel1.Width, 0), Color.Black, Color.White)
        e.Graphics.FillRectangle(b, Panel1.ClientRectangle)

        b.Dispose()
    End Sub

C#:
		private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			Brush b;

			b = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(panel1.Width, 0), Color.Black, Color.White);
			e.Graphics.FillRectangle(b, panel1.ClientRectangle);

			b.Dispose();
		}
 
Is it faster and more efficient in a program to draw a linear gradient, or to create the gradient as a jpg and put it in a picture box? The graident I am using is 512x50 so it is not very big.
 
Back
Top