È possibile utilizzare Utilizzare questo "fatto in casa" di classe. Per un corretto funzionamento, è necessario disporre di un contenitore e di un elemento di ridimensionamento al suo interno, come un'immagine sottile che funziona come un bordo di ridimensionamento. ControlToResize è il contenitore stesso. Puoi mettere tutto ciò che vuoi nel controllo. Esempio:
ControlResizer.Init(myPictureBox, myTableLayoutPanel, ControlResizer.Direction.Vertical, Cursors.SizeNS);
Qui è la classe.
class ControlResizer
{
public enum Direction
{
Horizontal,
Vertical
}
public static void Init(Control resizer, Control controlToResize, Direction direction, Cursor cursor)
{
bool dragging = false;
Point dragStart = Point.Empty;
int maxBound;
int minBound;
resizer.MouseHover += delegate(object sender, EventArgs e)
{
resizer.Cursor = cursor;
};
resizer.MouseDown += delegate(object sender, MouseEventArgs e)
{
dragging = true;
dragStart = new Point(e.X, e.Y);
resizer.Capture = true;
};
resizer.MouseUp += delegate(object sender, MouseEventArgs e)
{
dragging = false;
resizer.Capture = false;
};
resizer.MouseMove += delegate(object sender, MouseEventArgs e)
{
if (dragging)
{
if (direction == Direction.Vertical)
{
minBound = resizer.Height;
maxBound = controlToResize.Parent.Height - controlToResize.Top - 20;
controlToResize.Height = Math.Min(maxBound , Math.Max(minBound, controlToResize.Height + (e.Y - dragStart.Y)));
}
if (direction == Direction.Horizontal)
{
minBound = resizer.Width;
maxBound = controlToResize.Parent.Width - controlToResize.Left - 20;
controlToResize.Width = Math.Min(maxBound, Math.Max(minBound, controlToResize.Width + (e.X - dragStart.X)));
}
}
};
}
}
fonte
2013-01-22 21:14:05
Leggere questo post. Forse può aiutarti .. http://stackoverflow.com/questions/17264225/how-can-user-resize-control-at-runtime-in-winforms – Kix46
Prova questo link: http: // stackoverflow .com/questions/17264225/how-can-user-resize-control-at-runtime-in-winforms – Kix46