14,330,375 members
Rate this:
See more:
I want to add shadow on line in different angle of the line
TopLeft,
TopCenter,
TopRight,
MiddleLeft,
MiddleCenter,
MiddleRight,
BottomLeft,
BottomCenter,
BottomRight

How can i do that ?

What I have tried:

```GraphicsPath path = new GraphicsPath();
using (Graphics G = this.CreateGraphics())
{
var myPen = new Pen(Color.SkyBlue, 50);
G.DrawLine(myPen, new Point(10, 200), new Point(200, 200));

}

void drawShadow(Graphics G, Color c, GraphicsPath GP, int d)
{
Color[] colors = getColorVector(c, this.BackColor, d).ToArray();
for (int i = 0; i < d; i++)
{
G.TranslateTransform(0, 1);                // <== shadow vector!

using (Pen pen = new Pen(colors[i], 1.75f))  // <== pen width (*)
G.DrawPath(pen, GP);
}
G.ResetTransform();

}

List<Color> getColorVector(Color fc, Color bc, int depth)
{
List<Color> cv = new List<Color>();
float dRed = 1f * (bc.R - fc.R) / depth;
float dGreen = 1f * (bc.G - fc.G) / depth;
float dBlue = 1f * (bc.B - fc.B) / depth;
for (int d = 1; d <= depth; d++)
cv.Add(Color.FromArgb(255, (int)(fc.R + dRed * d),
(int)(fc.G + dGreen * d), (int)(fc.B + dBlue * d)));
return cv;
}```
Posted
Richard MacCutchan 17-Jan-17 4:28am

What is the question?
srilekhamenon 17-Jan-17 5:01am

What to create shadow according to the argument for line
Ramza360 17-Jan-17 11:35am

How big of a shadow are you making here if your doing the TranslateTransform(0, 1) in a for loop? If you need a single shadow, just get the shadow color, and draw the text at an offset, before drawing your main text

The offset could be (x + 1, y + 1) for bottom-right, (x - 1, y + 1) for bottom-left, or (x + i, y + i) if your doing many times though would need to switch the loop to for (int i = d; i > -1; i--){}

Rate this:

## Solution 1

v4

Top Experts
Last 24hrsThis month
 OriginalGriff 244 Richard MacCutchan 145 Patrice T 126 RickZeeland 125 CPallini 110
 OriginalGriff 2,313 Maciej Los 1,330 phil.o 958 Richard Deeming 590 Richard MacCutchan 401

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100