Solved

3-toned lines in .NET?

Posted on 2013-05-15
2
220 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now