[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

3-toned lines in .NET?

Odd question.  I've been playing around with this and haven't seen a solution.  

In .NET using GDI commands, you can draw a line using a built in pattern (dash, dot-dash, etc) or a custom pattern.  I THINK I've seen (but couldn't find again) a way to make the "blank" space between dashes, etc a specific color (rather than transparent) so that you can alternate between two colors.

Is there any built in way or trick to draw a single line with three colors, like red dash, green dash, blue dash?  Other than drawing three superimposed lines, I mean.

Thanks for any thoughts.
0
RonMexico
Asked:
RonMexico
1 Solution
 
CodeCruiserCommented:
I think there is no built in way of doing this and this has to be implemented by some technique such as drawing multiple lines of different colours.
0
 
Robert SchuttSoftware EngineerCommented:
The only way I can think of is using a TextureBrush. Drawing a line at an angle would get the wrong pattern so has to be done by using RotateTransform. Accuracy is not great I'm afraid. If you want to make a rectangle at an angle you would have to come up with a bit of math.
capture
        private void Form1_Load(object sender, EventArgs e) {
            DrawLinesRGB();
        }

        private void DrawLinesRGB() {
            Bitmap bm = new Bitmap(100, 100);
            Graphics g = Graphics.FromImage(bm);
            GraphicsPath p = new GraphicsPath();
            p.AddRectangle(new Rectangle(4, -1, 48, 2));

            Bitmap bmbr = new Bitmap(18, 3);
            Graphics gbr = Graphics.FromImage(bmbr);
            gbr.FillRectangle(new SolidBrush(Color.Red), 3, 0, 3, 3);
            gbr.FillRectangle(new SolidBrush(Color.Green), 9, 0, 3, 3);
            gbr.FillRectangle(new SolidBrush(Color.Blue), 15, 0, 3, 3);
            TextureBrush b = new TextureBrush(bmbr);

            g.TranslateTransform(50, 50);
            for (int c = 0; c < 12; c++) {
                g.FillPath(b, p);
                g.RotateTransform(30);
            }
            g.ResetTransform();

            this.panel1.BackgroundImage = bm;
        }

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now