Search code examples
c#.netwinformsgdi+gdi

How do I draw an X?


So I tried to draw an X:

e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
e.Graphics.DrawLine(new Pen(Color.Black, 1), 
                     this.Width + 20 - 50,  
                     20,  
                     this.Width + 25 - 50, 
                     10);

e.Graphics.DrawLine(new Pen(Color.Black, 1),  
                     this.Width - 20 + 50,  
                     20,  
                     this.Width + 25 - 50, 
                     10);

But it looks like an Axe. No matter which values I put for the second line code, it's just not right.


Solution

  • 10 x 10 X just add the position self

    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    e.Graphics.DrawLine(new Pen(Color.Black, 1), 
                         1,  
                         1,  
                         10, 
                         10);
    
    e.Graphics.DrawLine(new Pen(Color.Black, 1),  
                         1,  
                         10,  
                         10, 
                         1);