C#画线并调整表格形状 [英] C# painting lines and rezising the form
本文介绍了C#画线并调整表格形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
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));
}
并且panel1固定在左,右
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
例如在调整大小时
看起来像什么:----
它最终看起来像:----
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: ----
推荐答案
您需要清除之前绘制的虚线.
尝试将以下代码添加到面板的调整大小方法中:
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();
}
为什么要用 panel1_Paint 方法编写此代码?
如果没有任何特定原因,则应自行在form_Load中编写代码.每当您重新调整表单大小时,这将停止调用 panel1_Paint 方法.
谢谢
鲁西
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
这篇关于C#画线并调整表格形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文