我有自己的控件,我需要通過拖動來調整運行時大小。調整底部和右邊框的大小我使用這個:在運行時調整大小控件
protected override void OnMouseDown(MouseEventArgs e)
{
SL = new System.Drawing.Point(Location.X + e.Location.X, Location.Y + e.Location.Y);
SP = new System.Drawing.Point(Location.X, Location.Y);
if (e.X <= m)
_OnLeft = true;
if (e.X >= Width - m)
_OnRight = true;
if (e.Y <= m)
_OnTop = true;
if (e.Y >= Height - m)
_OnBottom = true;
}
protected override void OnMouseMove(MouseEventArgs e)
{
// Change Width - right
if (_OnRight && (!_OnTop && !_OnBottom))
{
if (e.X <= 1)
return;
Width = e.X;
return;
}
// Change Height - bottom
if (_OnBottom && (!_OnLeft && !_OnRight))
{
if (e.Y <= 1)
return;
Height = e.Y;
return;
}
}
所有的工作正常。但我有頂部和左側調整大小的問題:
// Change Width - left
if (_OnLeft && (!_OnTop && !_OnBottom))
{
// Problem part - I don't know condition to return
if (Width + Left - e.X <= 1)
return;
Left += e.X - SL.X + SP.X;
// How to get right width
Width += Left - e.X;
return;
}
// Change Height - top
if (_OnTop && (!_OnLeft && !_OnRight))
{
// Problem part - I don't know condition to return
if (Height + Top - e.Y <= 1)
return;
Top += e.Y - SL.Y + SP.Y;
// How to get right height
Height += Top - e.Y;
return;
}
類似的東西。有想法?
你有什麼樣的問題? – 2012-01-18 15:11:32
如果(Height + Top - e.Y <= 1)返回**,我不知道停止調整**的條件。以及如何得到正確**身高**在這部分代碼... – justAuser 2012-01-18 15:25:13