Add gleiche Erweiterungen zu mehreren Steuerelementen in Winforms
Ich möchte einige Erweiterungen wie verschieben, Größe ändern, ... zu @ hinzufügPictureBox
, Label
, Panel
so was
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;
}
Ist es sowieso so, dass ich es wie eine Klasse schreibe und es für alle erbe, oder sollte ich 3 separate Klassen schreiben, wie die, die ich für das @ geschrieben habPictureBox
?