鼠标按下时自动滚动问题
我在自动滚动面板内有一个自定义控件。当用户控件超出面板宽度时,会出现滚动条。然后,当您滚动任意距离并在控件上按下鼠标时,滚动条会弹回到 0。有人知道为什么会这样吗?我很确定我不会尝试在任何地方更改滚动条的值...
谢谢
编辑:这似乎只发生一次,第一次单击它时,每次它都会按预期工作
编辑2:它也当您打开一个新窗口,然后返回到 C# 窗口时会发生这种情况
I have a custom control inside an autoscroll panel. When the user control extends beyond the width of the panel, the scroll bars appear. When you then scroll any distance, and mousedown on the control, the scrollbar snaps back to 0. Does any one know why that might be? I'm pretty sure I am not trying to change the value of the scrollbar anywhere...
Thanks
EDIT: This only appears to happen once, the first time you click on it, every other time it works as expected
EDIT 2: It also happens when you bring a new window up, and then go back to the C# window
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我为 VB.net 解决了这个问题。要尝试此操作,请创建一个 WinForms 项目并:
运行该项目,移动 Panel1 滚动条,然后单击 TextBox1 中的某些文本。当 Panel1 尝试将 TextBox 的左上角滚动到视图中时,TextBox1 会令人烦恼地跳转。现在将下面的代码放入 Form1 中并重复测试。好多了!这在 VB 2010 Express 中有效。
I worked this out for VB.net. To try this create a WinForms project and:
Run the project, move the Panel1 scrollbars around and then click on some text in TextBox1. TextBox1 will jump annoyingly as Panel1 tries to scroll the TextBox's upper left corner into view. Now place the code below into Form1 and repeat the test. Much nicer! This worked in VB 2010 Express.
如果您有一个比其容器宽得多的控件(例如
TextBox
),并且您滚动到它的末尾,然后单击该控件,您将滚动回到Location
的控制。单击的控件获得焦点并自动发生滚动,这是 winform 的标准行为。
如果您想否定这一点,则必须拦截容器 (
ScrollableControl
) 的SetAutoScrollPosition
或使用其他机制恢复到原始位置。如果控件已获得焦点,然后您滚动,则再次单击它不会更改容器的
AutoScrollPosition
。If you have a control (like a
TextBox
) that is much wider than it's container and you scroll to it's end, then click the control, you will be scrolled back to theLocation
of the control.The clicked control gains focus and the scrolling occurs automatically, that is standard behaviour of winforms.
If you want to negate that, you will have to intercept
SetAutoScrollPosition
of the container (ScrollableControl
) or use another mechanism to revert to the original position.If the control already has focus and you then scroll, clicking it again won't change the
AutoScrollPosition
of the container.