CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    3

    Question Question about GDI+. Thanks.

    How to draw a style line(bezier,polyline etc.) as:

    ----|----|----|----|----|----|----


    Thanks.

  2. #2
    Join Date
    Sep 2000
    Location
    Indianapolis
    Posts
    6,754
    This is not a complete answer to your question; however, I've included some code that is 1/2 your answer

    I'm guessing you'll want to set a dash pattern on your pen (DashPattern). You set this to an array of floats that gives the widths of the dashes and spaces.

    Create dash pattern:

    float[] dashValues = {3, 1, 3, 1, 3, 1, 3, 1};

    Set dash pattern on your pen

    myPen.DashPattern = dashValues;

    Set DashStyle to custom

    myPen.DashStyle = DashStyle.Custom;

    Draw your line.

    The following code can be placed in a C# application with a button called btnGo.


    Code:
    private void btnGo_Click(object sender, System.EventArgs e)
    {
       Graphics g = this.CreateGraphics();
       g.Clear(this.BackColor);
    
       // Create pen
       Pen myPen = new Pen(Color.Blue, 3);
    
       // Following uses standard styles:
    
       myPen.DashStyle = DashStyle.Dash;
       myPen.DashOffset = 40;
       myPen.DashCap = DashCap.Triangle;
       g.DrawLine (myPen, 10, 10, (Form1.ActiveForm.Width - 10), 10);
       myPen.DashStyle = DashStyle.DashDot;
       g.DrawLine(myPen, 10, 30, (Form1.ActiveForm.Width - 10), 30);
       myPen.DashStyle = DashStyle.Dot;
       g.DrawLine(myPen, 10, 50, (Form1.ActiveForm.Width - 10), 50);
       myPen.DashStyle = DashStyle.Dash;
       g.DrawLine(myPen, 10, 70, (Form1.ActiveForm.Width - 10), 70);
       myPen.DashStyle = DashStyle.DashDotDot;
       g.DrawLine(myPen, 10, 90, (Form1.ActiveForm.Width - 10), 90);
       myPen.DashStyle = DashStyle.Custom;
       g.DrawLine(myPen, 10, 110, (Form1.ActiveForm.Width - 10), 110);
    
       // custom
       // pen width...
       int myPenWidth = 2;
       myPen.Color = Color.Green;
       myPen.Width = myPenWidth;
       // set a float array to widths you want custom dashes...
       // first value draw width, second space, third draw, etc.
       float[] dashValues = {myPenWidth*2, myPenWidth, myPenWidth*2, myPenWidth,
                   myPenWidth*2, myPenWidth, myPenWidth*2, myPenWidth };
       // set dash pattern on your pen
       myPen.DashPattern = dashValues;
       // set DashStyle to custom
       myPen.DashStyle = DashStyle.Custom;
       g.DrawLine(myPen, 10, 130, (Form1.ActiveForm.Width - 10), 130);
    	
       // Displose
       myPen.Dispose();
       g.Dispose();
    }

    Don't know if this helps, or if is stuff you knew.

  3. #3
    Join Date
    Jul 2004
    Posts
    3

    thank,Brad Jones.

    But the vertical line not draw in the dash line.



    ----|----|----|----
    or
    ----O----O----O----
    or
    ----text----text----text----

  4. #4
    Join Date
    Feb 2010
    Posts
    1

    Re: Question about GDI+. Thanks.

    Hi
    What is the way to draw custom dash style cap (not triangles or circlse) something like this
    ---- | --- | --- |
    or
    ---- # --- # --- #
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured