【发布时间】:2017-06-21 09:01:13
【问题描述】:
我在状态栏中有两个(或通常为n 数量)状态面板。
该状态栏将始终根据托管 Windows 窗体大小进行调整大小。
现在,如何确保每个(或所有n 个)状态面板获得相同的状态栏宽度,以及如何确保它们从左到右很好地堆叠为在Panels 对象中按顺序表示?
【问题讨论】:
我在状态栏中有两个(或通常为n 数量)状态面板。
该状态栏将始终根据托管 Windows 窗体大小进行调整大小。
现在,如何确保每个(或所有n 个)状态面板获得相同的状态栏宽度,以及如何确保它们从左到右很好地堆叠为在Panels 对象中按顺序表示?
【问题讨论】:
只需添加一个函数即可将面板大小调整为表单上的Resize 事件。对于两个面板,您只需在表单的初始化函数中添加类似的内容来处理调整大小。 (使用 C#)
//To find to width of each panel, subtract 30 (or so, but your panels need to leave a little
//space) from the width of the form, and then divide by number of panels.
//Initialize the panel widths (If they aren't correct already)
statusBarPanel1.Width = statusBarPanel2.Width = (Width - 30) / 2;
//Make the panel widths update if the form is resized
Resize += (s, e) => statusBarPanel1.Width = statusBarPanel2.Width = (Width - 30) / 2;
面板的顺序不应改变,因此您无需担心。
【讨论】: