You need to specify that you want your Pen
to draw dashed using Pen.DashStyle
:
TotaldashLine.Pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
Once you have done that, you can additionally customize the lengths of dashes and gaps using the Pen.DashPattern
as you have.