2010-10-04 41 views

回答

2

我觉得你必须自己实现

  1. 上按下鼠标开始拖动鼠标+改变光标绑定来调整鼠标拖动图标
  2. ,只是简单地减少对鼠标的形状大小
  3. 了解除绑定鼠标拖动事件

的原因,我建议动态事件绑定,这样你们可以指定其控制或区域应具备鼠标按下

+0

我已经实施了几天前相同的方式重新大小。但我想我应该选择你的答案,因为你是第一个在这里发帖的人。 – 2010-10-20 06:34:24

0

无边框(或控制),你打算如何调整?图将这部分分离出来,那就试试这个代码在您的形式:

public class CustomForm : Form 
{ 
    private const int WmNcLButtonDown = 0xA1; 
    private const int HtBottomRight = 17; 

    [DllImport("user32.dll")] 
    private static extern int ReleaseCapture(); 

    [DllImport("user32.dll")] 
    private static extern int SendMessage(IntPtr hwnd, int msg, int wparam, int lparam); 

    // elsewhere 
    void ResizeForm() 
    { 
     ReleaseCapture(); 
     SendMessage(this.Handle, WmNcLButtonDown, HtBottomRight, 0); 
    } 
} 

此代码将调整您的形式,虽然使用了右下角。查找不同位置的HT_BOTTOMRIGHT和其他HT_常量来调整大小。

1

我不确定阴影效果,但您应该可以通过在右下角放置一个按钮并使用某个适当的图标来调整窗体大小。当用户点击并拖动此按钮时,它将调整窗体大小。下面是一些示例代码:

public partial class Form1 : Form 
{ 
    private int bottomBorder; 
    private int rightBorder; 
    private Point mouseStart; 
    private bool isResizing = false; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_MouseMove(object sender, MouseEventArgs e) 
    { 
     if (isResizing) 
     { 
      var newLocation = button1.Location; 
      newLocation.Offset(
       e.X - mouseStart.X, 
       e.Y - mouseStart.Y); 
      button1.Location = newLocation; 
      this.Height = button1.Bottom + bottomBorder; 
      this.Width = button1.Right + rightBorder; 
      button1.Refresh(); 
     } 

    } 

    private void button1_MouseDown(object sender, MouseEventArgs e) 
    { 
     isResizing = true; 
     mouseStart = e.Location; 
    } 

    private void button1_MouseUp(object sender, MouseEventArgs e) 
    { 
     isResizing = false; 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     bottomBorder = this.Height - button1.Bottom; 
     rightBorder = this.Width - button1.Right; 
    } 
} 
+0

一个更精确。 – 2010-10-20 06:37:32

0

我用唐柯比和马修·费雷拉的解决方案,并创建了自己的解决方案结合两者。我添加了一个名为“resizeHandle”的StatusStrip,使其尺寸为20x20像素并听取它的事件。

public class CustomForm : Form 
{ 
private const int WmNcLButtonDown = 0xA1; 
private const int HtBottomRight = 17; 
private const int wmNcLButtonUp = 0xA2; 
private bool isResizing = false; 

[DllImport("user32.dll")] 
private static extern int ReleaseCapture(); 

[DllImport("user32.dll")] 
private static extern int SendMessage(IntPtr hwnd, int msg, int wparam, int lparam); 

private void resizeHandle_MouseDown(object sender, MouseEventArgs e) 
{ 
    isResizing = true; 
} 

private void resizeHandle_MouseMove(object sender, MouseEventArgs e) 
{ 
    if (isResizing) 
    { 
     // Check if we have released the Left mouse button 
     isResizing = (e.Button == MouseButtons.Left); 
     ReleaseCapture(); 
     if (isResizing) 
     { 
      SendMessage(Handle, wmNcLButtonDown, HtBottomRight, 0); 
     } 
     else 
     { 
      // Left Mouse button was released, end resizing. 
      SendMessage(Handle, wmNcLButtonUp, HtBottomRight, 0); 
     } 
    } 
}