Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

c# - How can I remove the border padding on container controls in WinForms?

I set margin and padding to 0 0 0 0 but that doesn't have any effect for my TabControls. Look:

enter image description here

Here is what I am talking about. I want to stick the borders together.

How can I do this?

@Henk Holterman - yes, what's wrong with it ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's a comment left in the source code for TabPage by an exasperated Microsoft programmer (edited to fit the page):

//HACK: to ensure that the tabpage draws correctly (the border will get 
//  clipped and gradient fill will match correctly with the tabcontrol).
//  Unfortunately, there is no good way to determine the padding used 
//  on the tabpage.
//  I would like to use the following below, but GetMargins is busted 
//  in the theming API:
//VisualStyleRenderer visualStyleRenderer = new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal);
//Padding themePadding = visualStyleRenderer.GetMargins(e.Graphics, MarginProperty.ContentMargins);

Visual Styles have been a major bug factory, particularly so for TabControl. Check this answer for a way to selectively turn it off for the TabControl so you'll get the behavior you are used to. Of course it does change the appearance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...