通用问题
应用程序是C# WinForms .Net 4.0。
我有一个SplitContainer,它占据了大部分的表单,它被设置为各个方向的锚,所以它和表单一起调整大小。左面板(Panel1)有一个简单的菜单,这里没有问题。右侧面板(Panel2)更复杂,包含许多嵌套的选项卡控件(包含大量控件)--它非常复杂,但没有改变。
问题是重新调整表单的大小不太好。事实上,如果您通过缓慢拖动边缘来调整大小,那么它可以正常工作,但是可以快速拖动或使用“还原”按钮(窗体的右上角),那么问题就会发生。
我的控制层次结构
下面是我的控件层次结构的一个简单示例,它肯定是一个精简版本,但是突出显示了可能有助于复制的嵌套选项卡控件:
- SC Panel2
- Panel (anchor: top, left, bottom, right)
- Tab Control (anchor: top, left, bottom, right)
- Tab Control w/ lots of pages that overflow screen and require the navigation buttons to show in top right corner (anchor: top, left, bottom, right)
调试详细信息
经过一些调试后,实际上似乎是Panel2 (拆分容器的一个子容器)没有正确调整大小,而实际的SplitContainer本身大小调整得很好。
下面的调试值显示了.
调整大小前的全宽度窗体:
splitContainerMain.Width: 1479
splitContainerMain.Panel2.Width: 1206
panelCenter.Width: 1203
tabControlMain.Width: 1215正如预期的那样,splitContainerMain.Panel2.Width比splitContainerMain.Width小。
在调整问题发生时的大小后:
splitContainerMain.Width: 815
splitContainerMain.Panel2.Width: 1206
panelCenter.Width: 1203
tabControlMain.Width: 1215可以看到,splitContainerMain.Width已经根据需要调整了大小,但是splitContainerMain.Panel2.Width及其子程序却没有。
备注:请记住,如果我手动调整表单的大小,则宽度更新是正确的--这不是我没有正确设置任何锚点的问题。
我的努力到目前为止
我尝试做的是使用各种形式调整事件大小,并尝试手动设置宽度,但没有效果。我想我想尝试的是从某种事件中设置Panel2.Width值。
我在找什么
splitContainerMain.Panel2.Width在splitContainerMain大小更改时正确调整大小的情况?Panel2.Width应该是什么?如何从Form.Resize事件中设置该值?(或者其他事件?)发布于 2019-03-20 10:31:28
虽然我的问题是6岁左右,但我选择回答这个问题,是因为我的情况与开幕职位相同。不幸的是,没有指定方向。所以,我的回答是针对那些横向方向的。
请翻译成C#,因为这段代码在VB中。
Private Sub splitContainerMain_Resize(sender As Object, e As EventArgs) Handles splitContainerMain.Resize
'/* This is a work around about panels being left out when SplitContainer is resized */
Dim pnl1Height As Single = splitContainerMain.SplitterDistance '/* Get upper panel height */
Dim pnl2Height As Single = splitContainerMain.Height - splitContainerMain.SplitterDistance '/* Get lower panel height */
splitContainerMain.Panel1.SetBounds(0, 0, splitContainerMain.Width, pnl1Height) '/* Set Upper panel bounds */
'/* Set lower panel bounds, with a top of upper panel height plus splitter width */
splitContainerMain.Panel2.SetBounds(0, pnl1Height + splitContainerMain.SplitterWidth, splitContainerMain.Width, pnl2Height)
End Sub发布于 2014-11-28 07:15:30
据我所见,对于正在产生问题的控件,您应该将锚设置为none,包括拆分容器pannels。
另外,我建议使用dock属性来最好地使用拆分容器。
如果需要进一步的帮助,请提供设计师的文件,这样可以有一个更好的外观。
发布于 2019-01-19 19:21:11
因此,对于每个要创建新线程的更改事件,该线程将等待100 ms,然后再进行接收?那太蠢了。您可以在构造函数中创建一个线程,然后在线程上调用Start(),该线程可能具有以下内容:
private void resizeMe()
{
this.BeginInvoke((Action)() => {
splitContainer.Height = tableBorder.Height;
splitContainer.Width = tableBorder.Width;
}
}https://stackoverflow.com/questions/18079004
复制相似问题