【问题标题】:Two status panels inside a status bar, how to make sure they are always each taking half of the status bar?一个状态栏内的两个状态面板,如何确保它们始终占据状态栏的一半?
【发布时间】:2017-06-21 09:01:13
【问题描述】:

我在状态栏中有两个(或通常为n 数量)状态面板。

该状态栏将始终根据托管 Windows 窗体大小进行调整大小。

现在,如何确保每个(或所有n 个)状态面板获得相同的状态栏宽度,以及如何确保它们从左到右很好地堆叠为在Panels 对象中按顺序表示?

【问题讨论】:

    标签: winforms statusbar


    【解决方案1】:

    只需添加一个函数即可将面板大小调整为表单上的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;
    

    面板的顺序不应改变,因此您无需担心。

    【讨论】:

    • 我尝试了您的建议,方法是在表单构造函数和表单加载事件中手动设置面板宽度,但均无效。
    • 它在我的测试中有效。您还在 Form Resize 事件中设置宽度,对吧?
    猜你喜欢
    • 2021-01-19
    • 2020-08-14
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 2011-02-22
    • 2015-08-31
    相关资源
    最近更新 更多