Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Gurus*
Posted

   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

 

	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();
	}

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...