Search code examples
.netwinformsdrawinglinedelphi-prism

How to draw a transparent line on Winform?


I would like to draw a transparent line on a winform.

I am able to draw lines with different patterns or DashStyle with following code:

 var r := new Rectangle(0,0,0,0);
 var thepen := new pen(color.black,3);
 pen.Dashstyle:= System.Drawing.Drawing2D.DashStyle.Dash;

 r := e.Bounds;
 var beginPoint := new Point( 0, r.Top + r.Height / 2 );
 var endPoint := new Point( r.Right, r.Top + r.Height / 2 );
 e.Graphics.DrawLine( thepen, beginPoint, endPoint );

But I need to also draw Transparent line and I don't know how. I've looked online and it seems there is hardly any information even in MSDN library


Solution

  • As suggested by Hans Passant, Color.Transparent works great, but you have to either add extra lines of code or come up with screwy logic to make that work especially when dealing with HatchBrush and SolidBrush. However, it works.