Bạn có thể sử dụng này "home made" class. Đối với một chức năng chính xác bạn shuld có một container và một yếu tố resizer bên trong nó, giống như một hình ảnh mỏng làm việc như một biên giới thay đổi kích thước. ControlToResize là chính vùng chứa. Bạn có thể đặt tất cả những gì bạn muốn trong điều khiển. Ví dụ:
ControlResizer.Init(myPictureBox, myTableLayoutPanel, ControlResizer.Direction.Vertical, Cursors.SizeNS);
Đây là lớp học.
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)));
}
}
};
}
}
Nguồn
2013-01-22 21:14:05
Hãy xem bài đăng này của tôi. Có thể nó có thể giúp bạn .. http://stackoverflow.com/questions/17264225/how-can-user-resize-control-at-runtime-in-winforms – Kix46
Hãy thử liên kết này: http: // stackoverflow .com/questions/17264225/how-can-user-resize-control-at-runtime-in-winforms – Kix46