关于 TableLayoutPanel 的 Scroll bar
2009-02-25 21:57
246 查看
为简化多个控件的布局,我在项目中使用了 TableLayoutPanel,并且设置了 AutoScroll = true,以实现滚动条功能。QA 在测试过程中发现两个问题:
TableLayoutPanel 内容过多时,达到某一个高度后,其下的所有行都不能正确显示。
使用鼠标移动滚动条,再切换到另一个窗体或程序,重新激活该窗体后滚动条又恢复到最初状态,页面保持在最上方。
通过了多次 Google,基本搞清楚了是什么原因:
这是 TableLayoutPanel 的一个 bug,经过测试,FlowLayoutPanel 也存在同样的问题。一个老外也遇到了同样的问题,并提供了解决方法:
While I didn't figure out why FlowLayoutPanel doesn't draw the items below a certain point, I found a workaround.
Attach an event handler to Scroll, where you perform FlowLayoutPanel.PerformLayout() and it will draw the controls when you get to them.
原以为也是 Microsoft 的 Bug,可是看了官方的回复,我也只有 workaround 了。
Due to the fact that it is the previously shipped behavior of Form to always scroll the active control into view when the Form is activated, we will not be able to change this. We can consider a property to disable this functionality, but this feature will not make the Whidbey release. We will consider it for a future release.
下面是解决该上面问题的代码,供参考:
private void WFPanel_Load(object sender, EventArgs e)
{
flpCharts.MouseWheel += flpCharts_MouseWheel;
}
private void flpCharts_MouseWheel(object sender, MouseEventArgs e)
{
flpCharts.Focus();
}
private void flpCharts_Scroll(object sender, ScrollEventArgs e)
{
flpCharts.PerformLayout();
flpCharts.Focus();
}
其中,Scroll 事件的第一和第二行代码,分别是为了解决前面提到的两个问题。而 MouseWheel 事件,则是为了处理第二个问题使用鼠标滚轮的场合。因为 MouseWheel 事件在 Designer 中找不到,只有在 Load 事件中手动注册了。
TableLayoutPanel 内容过多时,达到某一个高度后,其下的所有行都不能正确显示。
使用鼠标移动滚动条,再切换到另一个窗体或程序,重新激活该窗体后滚动条又恢复到最初状态,页面保持在最上方。
通过了多次 Google,基本搞清楚了是什么原因:
这是 TableLayoutPanel 的一个 bug,经过测试,FlowLayoutPanel 也存在同样的问题。一个老外也遇到了同样的问题,并提供了解决方法:
While I didn't figure out why FlowLayoutPanel doesn't draw the items below a certain point, I found a workaround.
Attach an event handler to Scroll, where you perform FlowLayoutPanel.PerformLayout() and it will draw the controls when you get to them.
原以为也是 Microsoft 的 Bug,可是看了官方的回复,我也只有 workaround 了。
Due to the fact that it is the previously shipped behavior of Form to always scroll the active control into view when the Form is activated, we will not be able to change this. We can consider a property to disable this functionality, but this feature will not make the Whidbey release. We will consider it for a future release.
下面是解决该上面问题的代码,供参考:
private void WFPanel_Load(object sender, EventArgs e)
{
flpCharts.MouseWheel += flpCharts_MouseWheel;
}
private void flpCharts_MouseWheel(object sender, MouseEventArgs e)
{
flpCharts.Focus();
}
private void flpCharts_Scroll(object sender, ScrollEventArgs e)
{
flpCharts.PerformLayout();
flpCharts.Focus();
}
其中,Scroll 事件的第一和第二行代码,分别是为了解决前面提到的两个问题。而 MouseWheel 事件,则是为了处理第二个问题使用鼠标滚轮的场合。因为 MouseWheel 事件在 Designer 中找不到,只有在 Load 事件中手动注册了。
相关文章推荐
- 关于TableLayoutPanel 单元格合并的解决方案。
- 关于TableLayoutPanel里放入控件无法将Dock设为Fill的解决办法
- c# winForm TableLayoutPanel学习 合并行的布局及动态增加删除内部控件
- 关于AndroidStudio中引用AndroidLibrary(Module)的方法 ——以一个github上的SlidingUpPanelLayout为例。
- 关于TableLayout的注意点:
- ADF 关于panelFormLayout 和panelGroupayout
- WinForm"tableLayoutPanel和flowLayoutPanel的使用"
- c# TableLayoutPanel控件应用 动态添加控件及事件
- C# TableLayoutPanel 一个很实用的案例
- tableLayoutPanel的单元格设置
- TableLayoutPanel闪烁问题解决
- C# TableLayoutPanel让一个控件占两行或者两列
- C# TableLayoutPanel 添加、删除一行数据案例
- 使用 TableLayoutPanel 在 Windows 窗体上自动排列控件
- c# winForm TableLayoutPanel学习 合并行的布局及动态增加删除内部控件
- WinForm"tableLayoutPanel和flowLayoutPanel的使用(附源码示例)" 之配餐系统的开发
- TableLayoutPanel 不能获取焦点
- 解决TableLayoutPanel控件闪烁
- TableLayoutPanel 常见操作
- C#笔记9——基于TableLayoutPanel的多分屏、全屏程序