Search code examples
winformswindows-forms-designerdocking

How can I keep a Status Bar from covering my RichTextBox?


there! I am creating a Notepad-Like program (much more advanced) and there is something bothering me...

Notepad++ & Notepad have the Status Bar located just under the RichTextBox/TextBox border. LITERALLY RIGHT UNDER IT.

I put a Status Bar onto my form, and added the controls (Lines, Line, Column, FileSize...) but I still cannot get it to stay under the RichTextBox, so that it will not block the user's view of text.

For EXAMPLE...

I have a RichTextBox, and a user loads a huge file into it. They scroll down to the very bottom, and the last one or two lines are covered by the Status Bar.

I want it to stay below the RichTextBox, so that it doesn't block the user's view. It seems sloppy and will cause my customers to demand refunds.


Solution

  • When docking controls inside a container, the priority of a docked control over another is regulated using their z-order. A Control with a higher priority (a lower position in the z-order) takes precedence in the layout over controls with a lower priority (a higher position in the z-order).

    Controls' Docking Priority

    See also the Remarks section of the Control.Dock Property.

    To assign the a higher priority, right-click on a docked Control and select SendToBack.
    A lower priority is assigned selecting BringToFront instead.

    In this specific case, an undocked RichTextBox was obscured by a StatusBar control (not a StatusStrip, there's a little diffference on how the z-order is assigned to these 2 controls), which is docked to Bottom as default.
    A solution is to dock the RichTextBox control, give it a lower priority by right-clicking it and selecting BringToFront.
    Repeat the operation on the StatusBar control, selecting in this case SendToBack. This will cause the StatusBar to take the whole bottom part of its Form container, while the RichTextBox control occupies the space left.
    The two controls don't overlap anymore and the layout is not compromised when the Form is resized.