【问题标题】:C# Remove padding from TabPages in Windows FormsC# 从 Windows 窗体中的 TabPages 中删除填充
【发布时间】:2012-04-04 20:05:48
【问题描述】:

标签页在边框和内部控件之间有一个填充。有没有办法去掉这个填充?

这是必要的,因为如果 TabControl 停靠在父容器中,它看起来会很糟糕。

我尝试了一些方法覆盖,但没有奏效。

【问题讨论】:

  • 我不确定填充,但你不能让 tabcontrol 的外部背景/边框与父容器相同,以便它融入。(即边框 = 无)跨度>
  • @JustinPihony 我尝试了“此答案”链接中的代码,它给了我一个 win2k 样式的 TabControl。以“Explorer”为参数,完全没有变化。 Kyra:TabControl 没有 Border 属性,TabPage 的 Border 默认设置为 None。

标签: c# .net winforms tabcontrol tabpage


【解决方案1】:

我发现可以使用WndProc

public class TabControl2 : TabControl
{
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == 0x1300 + 40)
        {
            RECT rc = (RECT)m.GetLParam(typeof(RECT));
            rc.Left -= 7;
            rc.Right += 7;
            rc.Top -= 2;
            rc.Bottom += 7;
            Marshal.StructureToPtr(rc, m.LParam, true);
        }
        base.WndProc(ref m);
    }
}

public struct RECT
{
    public int Left, Top, Right, Bottom;
}

【讨论】:

  • 这是朝着正确的方向发展,但正在移除边框。此外,顶部还有一个白色填充物。这对我来说产生了最干净的结果:stackoverflow.com/a/7785745/920511
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-17
  • 2019-01-23
相关资源
最近更新 更多