I want to add some extensions like move, resize,... to PictureBox
, Label
, Panel
like this:
public class LiveControl: PictureBox
{
private Point cur = new Point(0, 0);
public LiveControl()
{
ResizeRedraw = true;
MouseDown += (s, e) => { cur = new Point(e.X, e.Y); };
MouseMove += (s, e) => {
if (e.Button == MouseButtons.Left)
{
Control x = (Control)s;
x.SuspendLayout();
x.Location = new Point(x.Left + e.X - cur.X, x.Top + e.Y - cur.Y);
x.ResumeLayout();
}
};
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var rc = new Rectangle(this.ClientSize.Width - grab, this.ClientSize.Height - grab, grab, grab);
ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor, rc);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x84)
{
var pos = this.PointToClient(new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16));
if (pos.X >= this.ClientSize.Width - grab && pos.Y >= this.ClientSize.Height - grab)
m.Result = new IntPtr(17);
}
}
private const int grab = 16;
}
Is there anyway that I write it like a class and inherit it for all of them, or should I write 3 separate classes like the one I have written for the PictureBox
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…