日期:2014-05-17  浏览次数:20775 次

我就想知道怎么实现。。。(事件和方法)
本帖最后由 u011311854 于 2013-10-04 20:52:16 编辑
public partial class Form1 : Form
    {
       Point pt;
       public bool a ;
 
        public Form1()
        {
            InitializeComponent();
             
        }
 
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
          if (a==true)
          {
           Graphics dc = e.Graphics;
           Pen blue = new Pen(Color.Blue, 3);
           dc.DrawRectangle(blue, pt.X, pt.Y, 50, 50);
            
          }
 
          a = false;
            
        }
 
        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            a = false;
            pt.X = e.X;
            pt.Y = e.Y;
            this.Text = string.Format("鼠标位置:({0},{1})", pt.X, pt.Y);
 
        }
 
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            a = true;
            
        }
 
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            a = true;
        }


我想,鼠标抬起时,在panel上画,我想知道事件和画图的方法怎么调用。。。
这段代码,想通过a作为一个开关。但是实现不了。。。
谢谢!

------解决方案----