如何在Form_Load的表单中绘制一条线?
问题描述:
我想在Form上从一个点到另一点画一条线,并在Form_Load()事件(不使用Paint事件)中对其进行编码:
I want to draw a line from one point to another on a Form and code it in Form_Load() event (not use Paint event):
private void Form1_Load(object sender, EventArgs e)
{
Pen pen = new Pen(Brushes.Blue,1);
Graphics m = this.CreateGraphics();
m.DrawLine(pen, 0, 0, 100, 100);
}
但是当我跑步时,我没有任何结果!为什么?希望你能帮助我解决这个问题.谢谢.
But when i run, i dont get any result! Why? Hope you help me solve this problem. Thanks.
答
请参阅我对问题的评论.这根本不是Forms和System.Drawing
的工作方式.请查看我过去的答案:
在mdi子表单之间画线 [在面板上捕获图形 [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [
Please see my comment to the question. This is not how Forms andSystem.Drawing
work, not at all. Please see my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].—SA