Form_load事件处理程序的问题???? [英] Problem with Form_load event handler ????
本文介绍了Form_load事件处理程序的问题????的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了以下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Pen mypen = new Pen(Color.Black, 1);
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
g.Clip = new Region(new Rectangle(0, 0, 1280, 800));
g.DrawLine(mypen, 0, 0, 1280, 800);
}
}
}
推荐答案
button.click事件是否连接到处理程序?
Is the button.click event connected to the handler?
最好在Paint事件中绘制:
Its better to draw in the Paint-event:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private bool _drawLine = false;
public Form1()
{
InitializeComponent();
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.button1.Click += new System.EventHandler(this.button1_Click);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
if(_drawLine)
e.Graphics.DrawLine(Pens.Black, 0, 0, 1280, 800);
}
private void button1_Click(object sender, EventArgs e)
{
_drawLine = true;
this.Invalidate();
}
}
}
这篇关于Form_load事件处理程序的问题????的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文