惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
罗磊的独立博客
美团技术团队
B
Blog
量子位
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Vercel News
Vercel News
Blog — PlanetScale
Blog — PlanetScale
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题

博客园 - gucs

《应用框架的设计与实现——.NET平台》书评 《WCF Unleashed》的 AzRoles 演示代码 Tech Ed 2009,胡思乱想 Mac 双系统的时间设置问题 使用 gVim 遇到的第一个问题 Google notebook for Firefox 3.5 Fiddler & localhost Powerdesigner 12.5 对 SQL Server 2005 做反向工程时发生错误 VisualSVN Server 的 Apache 配置 ExplorerXP 在 Vista 下的设置 ReSharper 2.0.4 安装时的 1722 错误 禁用 Nero ShowTime 快捷键 使用 ModalPopupExtender 和 UpdatePanel 应注意的问题 NHibernate 和 ODP.NET 手动注册 DevExpress 8.2.3 控件到 Visual Studio 工具箱 PPStream caused an Access Violation (0xc0000005) in module VSFilter.dll at 001b:07610441. 隐藏 Windows Vista 的 Explorer 菜单栏 ReadOnly Controls do not post back properly 使用 ExtJs Extender Controls 遇到的第一个错误
关于 TableLayoutPanel 的 Scroll bar
gucs · 2009-02-25 · via 博客园 - gucs

为简化多个控件的布局,我在项目中使用了 TableLayoutPanel,并且设置了 AutoScroll = true,以实现滚动条功能。QA 在测试过程中发现两个问题:

  1. TableLayoutPanel 内容过多时,达到某一个高度后,其下的所有行都不能正确显示。
  2. 使用鼠标移动滚动条,再切换到另一个窗体或程序,重新激活该窗体后滚动条又恢复到最初状态,页面保持在最上方。

通过了多次 Google,基本搞清楚了是什么原因:

  1. 这是 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.

  2. 原以为也是 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 事件中手动注册了。