Dashed lines with custom caps

Dashed lines with custom caps

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:

' This statement assumes that you have imported the System.Drawing namespace' This code should run inside a Windows Form classDim gr As Graphics = Me.CreateGraphicsDim p1 As New Pen(Color.Black, 3)p1.DashStyle = Drawing.Drawing2D.DashStyle.Dashgr.DrawLine(p1, 10, 10, 200, 10)p1.DashStyle = Drawing.Drawing2D.DashStyle.DashDotgr.DrawLine(p1, 10, 30, 200, 30)p1.DashStyle = Drawing.Drawing2D.DashStyle.DashDotDotgr.DrawLine(p1, 10, 50, 200, 50)p1.DashStyle = Drawing.Drawing2D.DashStyle.Dotgr.DrawLine(p1, 10, 70, 200, 70)' Create a custom dash pattern.Dim sngArray() As Single = {4, 4, 8, 4, 12, 4}p1.DashPattern = sngArraygr.DrawLine(p1, 10, 90, 200, 90)' Display pens with nondefault caps.Dim p2 As New Pen(Color.Black, 8)p2.StartCap = Drawing.Drawing2D.LineCap.DiamondAnchorp2.EndCap = Drawing.Drawing2D.LineCap.ArrowAnchorgr.DrawLine(p2, 280, 30, 500, 30)p2.StartCap = Drawing.Drawing2D.LineCap.RoundAnchorp2.EndCap = Drawing.Drawing2D.LineCap.Roundgr.DrawLine(p2, 280, 70, 500, 70)' Destroy custom Pen objects.p1.Dispose()p2.Dispose()gr.Dispose()

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as