Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

3-toned lines in .NET?

Posted on 2013-05-15
2
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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