如何删除 WinForms 中容器控件的边框填充?

发布于 2024-10-16 17:15:34 字数 223 浏览 2 评论 0原文

我将边距和填充设置为 0 0 0 0 但这对我的 TabControls 没有任何影响。看:

在此处输入图像描述

这就是我正在谈论的内容。我想把边界粘在一起。

我该怎么做?

@Henk Holterman - 是的,有什么问题吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光与爱终年不遇 2024-10-23 17:15:34

一位愤怒的 Microsoft 程序员在 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 关闭它的方法,以便您会得到你习惯的行为。当然,它确实会改变外观。

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.

时光清浅 2024-10-23 17:15:34

我同意亨克的观点。容器控件周围有一个相同大小的边框(据我记得是 9 像素)。它存在的原因是为了防止您将控件压得太靠近边缘。如果您在顶部这样做,您的控件将距离顶部的选项卡标题太近。它看起来很愚蠢并且会让用户感到困惑。 WinForms 正在将您从自己手中拯救出来,而您甚至不知道这一点。这正是最初这样做的原因。

熟悉 Microsoft 的标准用户界面指南,特别是布局部分 。请注意所有控件(对话框窗口本身、选项卡控件等)周围都有边框吗? Visual C++资源编辑器中有7个对话框单元; WinForms 使用像素规范。

   示例选项卡控件,边缘有边框
    按钮控件周围的间距

I agree with Henk. There's a border of the same size (9 pixels to my recollection) all the way around the container control. The reason it's there is to prevent you from squashing controls up too close to the edge. If you did that at the top, your control would be far too close to the tab headers at the top. It would look silly and confuse the user. WinForms is saving you from yourself here, and you don't even know it. Exactly the reason it was done in the first place.

Familiarize yourself with Microsoft's standard user interface guidelines, specifically the section on layout. Notice how all of the controls (the dialog box window itself, the tab control, etc.) have a border around them? It's 7 dialog units in the Visual C++ Resource Editor; WinForms uses a pixel specification.

    sample tab control, with border around edges
    spacing around a button control

围归者 2024-10-23 17:15:34

试试这个

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; }

Try This

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; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文