我将margin和padding设置为0 0 0 0,但这对我的TabControls没有任何影响。看一下:
这就是我所说的。我希望将边框粘在一起。
我该怎么做?
@Henk Holterman - 是的,有什么问题吗?
这就是我所说的。我希望将边框粘在一起。
我该怎么做?
@Henk Holterman - 是的,有什么问题吗?
微软程序员在TabPage的源代码中留下了一条注释(已编辑以适应页面):
//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);
视觉样式一直是一个主要的错误制造工厂,尤其是对于TabControl而言。查看此答案,了解如何选择性地关闭TabControl的视觉样式,以便获得您所熟悉的行为。当然,这确实会改变外观。
public class TabControlEx : TabControl
{
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x1300 + 40)
{
RECT rc = (RECT)m.GetLParam(typeof(RECT));
rc.Left -= 0;
rc.Right += 3;
rc.Top -= 0;
rc.Bottom += 3;
Marshal.StructureToPtr(rc, m.LParam, true);
}
base.WndProc(ref m);
}
}
internal struct RECT { public int Left, Top, Right, Bottom; }