Solved

3-toned lines in .NET?

Posted on 2013-05-15
2
229 Views
Last Modified: 2013-05-17
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
Comment
Question by:RonMexico
2 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39170911
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
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39176280
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question