Click here to Skip to main content
14,330,375 members
Rate this:
Please Sign up or sign in to vote.
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();
            path.AddLine(10, 200, 200, 200);
            using (Graphics G = this.CreateGraphics())
            {
                var myPen = new Pen(Color.SkyBlue, 50);
                G.DrawLine(myPen, new Point(10, 200), new Point(200, 200));
                drawShadow(G, Color.Green, path, 25);
                
            }

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
Comments
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--){}

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

   
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




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