this.pictureBox.MouseUp += this.*** 的问题
public void InitializeComponent()
{
this.mu = new System.Windows.Forms.MouseEventHandler
(this.pictureBox_MouseUp);
this.mm = new System.Windows.Forms.MouseEventHandler
(this.pictureBox_MouseMove);
this.md = new System.Windows.Forms.MouseEventHandler
(this.pictureBox_MouseDown);
this.pictureBox.MouseUp += this.mu;
this.pictureBox.MouseMove += this.mm;
this.pictureBox.MouseDown += this.md;
}
我是一个初学者,请问一下以上代码是什么意思?为什么要这么做?
谢谢!
------解决方案--------------------初始化控件
给pictureBox添加MouseUp,MouseMove,MouseDown事件。
===================================================================
this.mu = new System.Windows.Forms.MouseEventHandler
(this.pictureBox_MouseUp);
新建一个委托,响应事件是pictureBox_MouseUp函数
this.pictureBox.MouseUp += this.mu;
MouseUp是事件,这句是把事件跟响应关联起来。
------解决方案--------------------更好理解一些的话,可以如下理解:
this.mu = new MouseEventHandler(this.pictureBox_MouseUp);
是声明了一个和this.pictureBox_MouseUp类型一致的一个指针,这个指针指向了方法体this.pictureBox_MouseUp;
然后让this.pictureBox.MouseUp 指向方法this.pictureBox_MouseUp:
this.pictureBox.MouseUp += this.mu;