如何从滚动停止的WinForms面板? [英] How can you stop a Winforms Panel from scrolling?

查看:199
本文介绍了如何从滚动停止的WinForms面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你把一个DataGridView即高一个面板,是300像素高,从而有在面板上的滚动条上400像素,然后向下滚动,使得网格的下半部分示出,然后在一个控制在面板外,然后在在网格线时,面板向上滚动到顶部和在网格错行被选中。

If you put a DataGridView that is 400 pixels high on a panel that's 300 pixels high, so that there's a scroll bar on the panel, then scroll down so that the lower half of the grid is shown, then click on a control outside the panel, then click on a line in the grid, the panel scrolls up to the top and the wrong row in the grid is selected.

这不只是一个DataGridView;它发生任何控制这比面板,如Infragistics的UltraWinGrid,格式文本框更高。我提出这与Infragistics的错误,但他们说这是一个Microsoft问题。

It's not just a DataGridView; it happens with any control that's higher than the panel, eg Infragistics UltraWinGrid, Rich Text Box. I raised it as a bug with Infragistics, but they say it's a Microsoft issue.

我已经使用的所有相关事件的控制试过,但事件触发前面板滚动发生。

I've tried using all the relevant events for the controls, but the Panel scroll happens before the events fire.

有什么建议?

推荐答案

我猜测你是设置面板,真正的AutoScroll属性。当你这样做的话,切换应用程序重置滚动位置为零和面板重置其位置。

I am guessing that you are setting the AutoScroll property of the panel to true. When you do so, switching applications resets the scroll position to zero and the panel resets its position.

如果您关闭自动滚动,并添加自己的滚动条可以设置滚动条的最大值和最小值,以匹配面板的需求,然后在滚动条的滚动事件中设置面板的滚动值。当你切换窗口这不复位。

If you switch off AutoScroll and add your own scrollbar you can set the scrollbar's maximum and minimum to match the requirements for the panel, then set the panel's scroll values in the Scroll event of the scrollbar. This is not reset when you switch windows.

是这样的:

private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
    panel1.VerticalScroll.Value = vScrollBar1.Value;
}

这是对我一个新的,我不得不重新创建它。我可能有一篇文章添加到我的网站吧: - )

This was a new one on me and I had to recreate it. I might have to add an article to my site about it :-)

这篇关于如何从滚动停止的WinForms面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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