110,476
社区成员
发帖
与我相关
我的任务
分享
//自定义控件的鼠标移动事件绑定方法
private void CTextBox_MouseMove(object sender, MouseEventArgs e)
{
if (isMoving)
{
//根据鼠标移动动态地设置控件的位置
if (this.Cursor == System.Windows.Forms.Cursors.SizeAll)
{
this.Location = new Point(this.Location.X + (e.X - offset.X),
this.Location.Y + (e.Y - offset.Y));
this.BackColor = Color.Red;
}
//根据鼠标移动动态地设置控件宽度 此处代码有效
if (this.Cursor == System.Windows.Forms.Cursors.SizeWE)
{
this.Width = intWidth + (e.X - offset.X);
this.BackColor = Color.Red;
}
//根据鼠标移动动态地设置控件高度 此处我属性添加了宽度 但是拖动的时候是无效的
if (this.Cursor == System.Windows.Forms.Cursors.SizeNS)
{
this.Height = intHeigh + (e.X - offset.X);
this.BackColor = Color.Red;
}
}
}