none
Why are ToolStrip and StatusStrip borders transparent? RRS feed

  • Question

  • I've added a ToolStrip and a StatusStrip to a TabControl's tab, with both docked ( one at top, other at the bottom ), and it seems the boarder of both of these tool items is transparent.  I'm drawing some GDI+ stuff on the client area and if drawn beneath these strips, I can see my drawing through the borders of these strips, as if they're transparent.  Perhaps I've missed some sort of property for both, but I can't seem to find it.

    Any ideas?
    Tuesday, March 9, 2010 4:31 AM

Answers

  • TabPage.SetBoundsCore gets its core size from TabControl.DisplayRectangle which gets its display rectangle from the system control itself. In other words, it is the Win32 tab control that is dictating there be a 3 pixel margin around your tab page. It would be difficult to fudge the page's core size as we don't know where the tab control gets the number 3 from (it might vary depending on OS settings).

    Two simple solutions:

    1) Add a Fill-docked panel to the page (you may have to use the Document Outline view to move the panel's z-order so that it fills without going under the tool strip or status bar). Use that panel to draw on (and contain any controls you might have).

    2) Calculate a clip rect that encompasses the tool strip and status bar before painting:

        tabControl1.TabPages[0].Paint += (object sender, PaintEventArgs e) =>
            {
                Rectangle newClip = Rectangle.Union(statusStrip1.Bounds, toolStrip1.Bounds);
                e.Graphics.SetClip(newClip);
                e.Graphics.FillRectangle(Brushes.Violet, (sender as Control).ClientRectangle);
            };
    
    • Marked as answer by eryang Monday, March 15, 2010 1:45 AM
    Tuesday, March 9, 2010 4:14 PM