using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace EastTicket.CustotmCol
{
class MovePanel:Panel
{
bool whetherSelected = false;
Point p = new Point();
public bool WhetherSelected
{
get { return whetherSelected; }
}
protected override void OnCreateControl()
{
base.OnCreateControl();
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
whetherSelected = true;
p.X = Cursor.Position.X;
p.Y = Cursor.Position.Y;
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (whetherSelected == true)
{
this.Left = this.Left + (Cursor.Position.X - p.X);
this.Top = this.Top + (Cursor.Position.Y - p.Y);
p.X = Cursor.Position.X;
p.Y = Cursor.Position.Y;
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
whetherSelected = false;
this.BringToFront();
}
}
}
实现控件的移动功能
最新推荐文章于 2023-04-13 23:49:53 发布