DefaultValue(true)]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.Drawing.Drawing2D;
namespace DariusArnold
{
public partial class MoveControl : Button
{
/// <summary>
/// Neue Instanz des bewegbaren Benutzersteuerelements.
/// </summary>
public MoveControl()
{
CanMove = true;
CanResize = true;
SnapsToGrid = true;
SizesToGrid = true;
ChangeCursor = true;
Grid = GridMode.ShowWhileMoving;
ViewGrid = GridViewingTypes.Draw;
CustomGridPixel = new bool[]{ false,
false,
false,
true,
true,
true,
true,
true,
false,
false };
GridColor = SystemColors.ControlDarkDark;
GridLineWidth = 2f;
GridDashStyle = DashStyle.Dot;
ResizeCornerSize = new Size(5, 5);
MinimumSize = new Size(20, 20);
AutoSize = false;
MarkResizeCorner = true;
ShowValueBoxes = true;
ResizeCornerMarkingColor = Color.Blue;
DoubleBuffered = true;
this.MouseDown += new MouseEventHandler(c_MouseDown);
this.MouseUp += new MouseEventHandler(c_MouseUp);
this.MouseMove += new MouseEventHandler(c_MouseMove);
this.Paint += new PaintEventHandler(c_Paint);
}
private int x, y;
private bool move, resize;
private Rectangle oControl = new Rectangle();
private Form form = null;
private GridMode gm = GridMode.ShowNever;
/// <summary>
/// Sets, if control can be moved during runtime.
/// </summary>
[CategoryAttribute("MoveAndResize"), DescriptionAttribute("Gibt an, ob das Element zur Laufzeit verschoben werden kann."), DefaultValue(true)]
public bool CanMove { get; set; }
/// <summary>
/// Sets, if control can be resized during runtime.
/// </summary>
[CategoryAttribute("MoveAndResize"), DescriptionAttribute("Gibt an, ob die Größe des Elements zur Laufzeit verändert werden kann."), DefaultValue(true)]
public bool CanResize { get; set; }
/// <summary>
/// Sets, if the control snaps to a 10x10 px grid automaticly.
/// </summary>
[CategoryAttribute("Grid"), DescriptionAttribute("Gibt an, ob sich das Element automatisch an einem 10x10-Raster ausrichten soll."), DefaultValue(true)]
public bool SnapsToGrid { get; set; }
/// <summary>
/// Sets, if the control's size is adapted to a 10x10 px grid automaticly.
/// </summary>
[CategoryAttribute("Grid"), DescriptionAttribute("Gibt an, ob die Größße des Elements automatisch an ein 10x10-Raster angepasst werden soll."), DefaultValue(true)]
public bool SizesToGrid { get; set; }
/// <summary>
/// Sets whether the cursor is changed if user moves the control or is able to resize it.
/// </summary>
[CategoryAttribute("Darstellung"), DescriptionAttribute("Gibt an, ob sich der Cursor ändern soll, wenn das Element verschoben wird oder seine Größe verändert werden kann."), DefaultValue(true)]
public bool ChangeCursor { get; set; }
/// <summary>
/// Sets, if the area to drag for resize the control is colored.
/// </summary>
[CategoryAttribute("Darstellung"), DescriptionAttribute("Gibt an, ob der "Angriffspunkt"" zur Größenänderung farbig hinterlegt werden soll."")
Alte URL:
/snippet/verschiebbares-und-groessenverstellbares-control/3832