如何在用C#在picturebox上用鼠标画线
如题 大家帮忙 我搜索了很多 但都是不是很清楚或者说我用的方法不对 private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{ }
是把代码写在这里面吗?
怎么没有反应呢 好象不起作用 大家帮忙
------解决方案--------------------public partial class Form1 : Form
{
private Point m_ptStart = new Point(0,0);
private Point m_ptEnd = new Point(0, 0);
private bool m_bMouseDown = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (!m_bMouseDown)
{
m_ptStart = new Point(e.X, e.Y);
m_ptEnd = new Point(e.X, e.Y);
}
m_bMouseDown = !m_bMouseDown;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (!m_bMouseDown) return;
m_ptEnd = new Point(e.X, e.Y);
this.pictureBox1.Refresh();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (m_ptStart.Equals(m_ptEnd)) return;
e.Graphics.DrawLine(System.Drawing.Pens.Black, m_ptStart, m_ptEnd);
}
}
够明白不?
------解决方案--------------------当然不能直接拷贝啦,你可能根本没有触发gudyn(子剑) 写的那三个事件。你选择pictureBox添加那三个事件。