Click here to Skip to main content
15,912,273 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
This is my code
private void panel1_Paint(object sender, PaintEventArgs e)
{
   float[] dashValues = { 2, 5, 2, 5 };
   Pen blackPen = new Pen(Color.Black, 2);
   blackPen.DashPattern = dashValues;
   e.Graphics.DrawLine(blackPen, new Point(panel1.Width, panel1.Height),
                       new Point(0, panel1.Height));
}


and panel1 is anchored left,right


this is my problem, when i size this form very slowly the dashes become very close together and don't leave a gap like it is supposed to

for example when re-sizing
what is meant to look like: - - - -

it ends up looking like: ----
Posted
Updated 24-Apr-12 3:52am
v2

You need to clear your previous dash line that you drew.

Try adding this code to the resize method of the panel:

private void panel1_Resize(object sender, EventArgs e)
{
    panel1.Invalidate();
}
 
Share this answer
 
Why are you writing this code in panel1_Paint method?

If there is no any specific reason then you should write your code in form_Load it self. This will stop calling panel1_Paint method every time you will re-size your form.

Thanks
Rushi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900