
























为简化多个控件的布局,我在项目中使用了 TableLayoutPanel,并且设置了 AutoScroll = true,以实现滚动条功能。QA 在测试过程中发现两个问题:
通过了多次 Google,基本搞清楚了是什么原因:
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.
下面是解决该上面问题的代码,供参考:
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 事件中手动注册了。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。