none
StatusStrip border disappears RRS feed

  • Question

  • This isn't making any sense.  I added a StatusStrip to my form, and when I changed its BackColor from Control to Window, the border above the control disappeared.  When I changed the BackColor back to Control, the border was still missing.  And there is no border property to tell it I want it to have a border.

    I looked at the code behind and the designer still had inserted code to change BackColor to Control.  So basically, if anything is assigned to BackColor, the border disappears.  What is up with that?

    Sunday, April 17, 2011 8:45 PM

Answers

  • Hi coryb891,

    The StatusStrip is derived from ToolStrip, and the ToolStripSystemRenderer will draw the ToolStrip controls at default.

    So we can use the Reflector disassemble the OnRenderToolStripBackground method in the ToolStripSystemRenderer class, then we can see that the background only render when the result of ShouldPaintBackground method is true, it is said that only when the Color is Empty or there's no background image, the render will draw the background.

    So we need to set the BackColor property to Color.Empty to let the render draw the background, when we want it.

    And for more knowledge about render, you can reference this document:

    http://msdn.microsoft.com/en-us/library/ms229634.aspx

    Best wishes,


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, April 19, 2011 8:22 AM
    Moderator
  • Just a little bit more clarifications based on Mike's last post...

    The ToolStripSystemRenderer uses the VisualStyleRenderer class to draw the ToolStrip background by default, that's where the "border" is drawn. That "border" is part of the standard visual appearance defined in the current windows theme.

    However, if the background has been assigned a custom color or image, the renderer will have to take care of the background painting itself, where no border will be drawn (remember the border is defined in the windows theme and now you're custom painting).

    And even if you assigned the bg color as SystemColors.Control it won't work as you expected, because the VisualStyleRenderer uses colors defined in the theme, not assigned by you. And since Color is a structure, you cannot assign null as the bg color, so Color.Empty is the correct choice.

    Back to your original problem, if you want the border, don't change the background color of the status bar so the system standard background will be used; or if you still want to use a customized color, you'll have to draw the border yourself.

    Regards,


    Jie Wang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

     
    Wednesday, April 20, 2011 3:20 AM

All replies

  • Hi coryb891,

    I can repro the same issue, but I have not found found why. And I'll try to research this issue.

     

    Currently, I think you can try to use DrawLine method to draw a line on the StatusStrip top(or on the Form, above the StatusStrip top) to solve this request.

     

    If there's any concern, please feel free to let me know.

    Best wishes,


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Monday, April 18, 2011 12:36 PM
    Moderator
  • Hi coryb891,

    The StatusStrip is derived from ToolStrip, and the ToolStripSystemRenderer will draw the ToolStrip controls at default.

    So we can use the Reflector disassemble the OnRenderToolStripBackground method in the ToolStripSystemRenderer class, then we can see that the background only render when the result of ShouldPaintBackground method is true, it is said that only when the Color is Empty or there's no background image, the render will draw the background.

    So we need to set the BackColor property to Color.Empty to let the render draw the background, when we want it.

    And for more knowledge about render, you can reference this document:

    http://msdn.microsoft.com/en-us/library/ms229634.aspx

    Best wishes,


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, April 19, 2011 8:22 AM
    Moderator
  • Just a little bit more clarifications based on Mike's last post...

    The ToolStripSystemRenderer uses the VisualStyleRenderer class to draw the ToolStrip background by default, that's where the "border" is drawn. That "border" is part of the standard visual appearance defined in the current windows theme.

    However, if the background has been assigned a custom color or image, the renderer will have to take care of the background painting itself, where no border will be drawn (remember the border is defined in the windows theme and now you're custom painting).

    And even if you assigned the bg color as SystemColors.Control it won't work as you expected, because the VisualStyleRenderer uses colors defined in the theme, not assigned by you. And since Color is a structure, you cannot assign null as the bg color, so Color.Empty is the correct choice.

    Back to your original problem, if you want the border, don't change the background color of the status bar so the system standard background will be used; or if you still want to use a customized color, you'll have to draw the border yourself.

    Regards,


    Jie Wang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

     
    Wednesday, April 20, 2011 3:20 AM
  • Hi coryb891,
    I am writing to check the status of the issue on your side. 
    What about this problem now? 
    Would you mind letting us know the result of the suggestions?
    Best wishes,

    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 26, 2011 1:35 AM
    Moderator