mcerk Posted April 24, 2005 Posted April 24, 2005 Hi. How can I draw a line with linear gradient. Let's say to start at color.Red and end with color.Blue tx, matej Quote
*Experts* mutant Posted April 24, 2005 *Experts* Posted April 24, 2005 Look into the System.Drawing.Drawing2D.LinearGradientbrush class. Here is an example: Graphics gr = this.CreateGraphics(); LinearGradientBrush br = new LinearGradientBrush(new Rectangle(0,0,100,100), Color.NavajoWhite, Color.Red, LinearGradientMode.Vertical); gr.FillRectangle(br, br.Rectangle); gr.Dispose(); Quote
mcerk Posted April 24, 2005 Author Posted April 24, 2005 Yes, I believed that drawing rectangle is maybe my only choice. But I have to draw a line. So I could draw very thin rectangle - I'll have some trouble with rotation, but I can firuge it out. brrrrrr.... I'll have to take a pen and paper into my hands and do some mathematics... Look into the System.Drawing.Drawing2D.LinearGradientbrush class. Here is an example: Graphics gr = this.CreateGraphics(); LinearGradientBrush br = new LinearGradientBrush(new Rectangle(0,0,100,100), Color.NavajoWhite, Color.Red, LinearGradientMode.Vertical); gr.FillRectangle(br, br.Rectangle); gr.Dispose(); Quote
*Experts* mutant Posted April 24, 2005 *Experts* Posted April 24, 2005 Oh, im sorry, for some reason I didn't think about you needing a line when i wrote the code :D. You can create a Pen object used to draw the line from the brush so that is not a problem. Graphics gr = this.CreateGraphics(); LinearGradientBrush br = new LinearGradientBrush(new Rectangle(0,0,100,100), Color.NavajoWhite, Color.Red, LinearGradientMode.Vertical); Pen lpen = new Pen(br, 1); gr.DrawLine(lpen,0,0,100,200); gr.Dispose(); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.