Solved

3-toned lines in .NET?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Need help on C# Linq query on object 6 53
Runtime Error 2 28
free scanner TWAIN can be operated with a Web application 9 39
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

22 Experts available now in Live!

Get 1:1 Help Now