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:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may

man on floor with data

DevX Quick Guide to Data Ingestion

One of the biggest trends of the 21st century is the massive surge in internet usage. With major innovations such as smart technology, social media, and online shopping sites, the internet has become an essential part of everyday life for a large portion of the population. Due to this internet

payment via phone

7 Ways Technology Has Changed Traditional Payments

In today’s digital world, technology has changed how we make payments. From contactless cards to mobile wallets, it’s now easier to pay for goods and services without carrying cash or using a checkbook. This article will look at seven of the most significant ways technology has transformed traditional payment methods.