Drawing shaded lines and shapes

  • Thread starter Thread starter John Baro
  • Start date Start date
J

John Baro

I wish to draw a line say 10px wide at a 45 degree angle (or any other
angle) and have it shaded say from gray to red to gray again (or any other
color).

I can get the line by using a GraphicsPath object but cannot work out the
shading part.

Is this also possible for say a circle with an outside line width of 10px to
be shaded from red to gray from the inside out around the circumference of
the circle.

TIA
JB
 
John Baro said:
I wish to draw a line say 10px wide at a 45 degree angle (or any other
angle) and have it shaded say from gray to red to gray again (or any other
color).

I can get the line by using a GraphicsPath object but cannot work out the
shading part.

Is this also possible for say a circle with an outside line width of 10px to
be shaded from red to gray from the inside out around the circumference of
the circle.

TIA
JB
 
how about something like :

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint (e);

Brush b = new LinearGradientBrush(new Point(10,10),new Point(100,100),
Color.Gray, Color.Red);

Pen p = new Pen(b,2);

e.Graphics.DrawLine(p,new Point(10,10),new Point(100,100));

Brush b1 = new LinearGradientBrush(new Point(100,100),new Point(200,200),
Color.Red, Color.Gray);

Pen p1 = new Pen(b1,2);

e.Graphics.DrawLine(p1,new Point(100,100),new Point(200,200));

}
 
Thanks for the reply Malek

I forgot to mention that it has to be shaded blue red blue along the axis of
the line.
i.e. if the line was flat then red along the top to blue in the middle and
back to red again at the bottom but again on a 45 angle.

Cheers
JB
 
something went wrong on my earlier answer, so here it is :

I guess something like this would do what you are looking for (this is for
lines, but you can do the same with aother shapes.)

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
Brush b = new LinearGradientBrush(new Point(10,10),new Point(100,100),
Color.Black, Color.Red);
Pen p = new Pen(b,10);
e.Graphics.DrawLine(p,new Point(10,10),new Point(100,100));
Brush b1 = new LinearGradientBrush(new Point(100,100),new
Point(200,200), Color.Red, Color.Black);
Pen p1 = new Pen(b1,10);
e.Graphics.DrawLine(p1,new Point(100,100),new Point(200,200));
}
 
trick it ... use rectangle for the line ...

John Baro said:
Thanks for the reply Malek

I forgot to mention that it has to be shaded blue red blue along the axis of
the line.
i.e. if the line was flat then red along the top to blue in the middle and
back to red again at the bottom but again on a 45 angle.

Cheers
JB

circumference
 
here is going from border to middle to border of the line ... (perpendicular
to the line)

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint (e);

Brush b = new LinearGradientBrush(new Point(50,40),new Point(50,50),
Color.Gray, Color.Red);

Pen p = new Pen(b,10);

e.Graphics.DrawLine(p,new Point(0,45),new Point(100,45));

Brush b1 = new LinearGradientBrush(new Point(50,50),new Point(50,60),
Color.Red, Color.Gray);

Pen p1 = new Pen(b1,10);

e.Graphics.DrawLine(p1,new Point(0,55),new Point(100,55));

}
 
use the method :
LinearGradientBrush (Rectangle rect, Color color1, Color color2, float
angle, bool isAngleScaleable)
 
Back
Top