Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Dashed lines with custom caps

Total Hit ( 4299)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


You can set properties of the Pen object to create custom lines. For example, you can use the DashStyle enumerated property to draw dashed lines using a predefined pattern, and you can even create custom dash patterns by assigning an array of Single values to the DashPattern property. The StartCap and EndCap properties can take an enumerated value and let you change the shape of the starting and ending point of the line so that you can easily create arrows or other common shapes. Here's a code that creates several lines with different styles:

Click here to copy the following block
' This statement assumes that you have imported the System.Drawing namespace

' This code should run inside a Windows Form class
Dim gr As Graphics = Me.CreateGraphics

Dim p1 As New Pen(Color.Black, 3)
p1.DashStyle = Drawing.Drawing2D.DashStyle.Dash
gr.DrawLine(p1, 10, 10, 200, 10)
p1.DashStyle = Drawing.Drawing2D.DashStyle.DashDot
gr.DrawLine(p1, 10, 30, 200, 30)
p1.DashStyle = Drawing.Drawing2D.DashStyle.DashDotDot
gr.DrawLine(p1, 10, 50, 200, 50)
p1.DashStyle = Drawing.Drawing2D.DashStyle.Dot
gr.DrawLine(p1, 10, 70, 200, 70)

' Create a custom dash pattern.
Dim sngArray() As Single = {4, 4, 8, 4, 12, 4}
p1.DashPattern = sngArray
gr.DrawLine(p1, 10, 90, 200, 90)

' Display pens with nondefault caps.
Dim p2 As New Pen(Color.Black, 8)
p2.StartCap = Drawing.Drawing2D.LineCap.DiamondAnchor
p2.EndCap = Drawing.Drawing2D.LineCap.ArrowAnchor
gr.DrawLine(p2, 280, 30, 500, 30)

p2.StartCap = Drawing.Drawing2D.LineCap.RoundAnchor
p2.EndCap = Drawing.Drawing2D.LineCap.Round
gr.DrawLine(p2, 280, 70, 500, 70)

' Destroy custom Pen objects.
p1.Dispose()
p2.Dispose()
gr.Dispose()


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.