-
July 21st, 2004, 11:04 AM
#1
Question about GDI+. Thanks.
How to draw a style line(bezier,polyline etc.) as:
----|----|----|----|----|----|----
Thanks.
-
July 21st, 2004, 05:59 PM
#2
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.
-
July 22nd, 2004, 12:18 AM
#3
thank,Brad Jones.
But the vertical line not draw in the dash line.
----|----|----|----
or
----O----O----O----
or
----text----text----text----
-
February 5th, 2010, 03:49 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|