移动控件时停止滚动表单 [英] Stop form from scrolling when moving controls

查看:54
本文介绍了移动控件时停止滚动表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有自动滚动功能的表单,并且该表单中有一个用户可编辑的区域.用户可以调整控件的大小或移动它们.

I have a form with autoscroll on, and I have a user-editable area in the form. Users can resize or move controls.

在移动控件时,如果将它们移到窗体的工作区之外,则会显示滚动条.这是我的意图.

When moving the controls, if they are moved beyond the form's client area, the scrollbars will show. This is my intention.

现在,表单将自动向下滚动,因此当用户不释放鼠标时,控件将继续向下移动.显然这不是故意的.

Now, the form will automatically scroll down, so while the user doesn't release the mouse, the control will keep being moved down. This is obviously not intended.

我尝试在移动(或调整大小)开始时禁用autoscrool,但效果不佳...如果控件超出了窗体的客户端范围,一旦移动开始,它就会向上(或向左)移动.

I have tried disabling autoscrool when the moving (or resizing) begins, but no good... If the control is beyond the form's client are, once the moving begins it gets moved up (or left).

当我移动子控件时,如何锁定scroolbar?

What is the way to lock the scroolbar when I am moving child controls?

---示例代码---

--- sample code---

仅是控件移动的示例.

//Start moving if the button is clicked on
public void Button1_OnMouseDown()
{
   _moving=true;

}


//If the button was clicked on, move it to mouse position
public void OnMouseMove(object sender, MouseEventArgs e)
{
     if(_moving)
         Button1.Location=new Poiny(e.X, e.Y);
}

当我移出表单的边界时,会出现scroolbars,并开始向下/向右滚动以适应控件...由于存在鼠标移动事件,因此又会移动控件,依此类推...

When I move out of the form's boundary, scroolbars appear and start rolling down/right to fit the controls... which in turn moves the controls since there is a mouse move event, and so on...

推荐答案

通过覆盖 ScrollToControl Form Panel 滚动>方法,例如:

You can prevent the Form or Panel from scrolling by overriding the ScrollToControl method, e.g:

protected override Point ScrollToControl(Control activeControl) {
    Point pt = this.AutoScrollPosition;
    return pt;
}

这篇关于移动控件时停止滚动表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆