C#选项卡控件边界控件

C#选项卡控件边界控件,c#,winforms,C#,Winforms,是否可以使tabcontrol边框透明,或设置tabcontrol的颜色 Winforms 如果有人遇到同样的问题,以下是对我有效的答案 正如它所描述的, 创建一个NativeTabControl对象,并指定要删除其边框的tabControl的句柄。可以将此NativeTabControl类用作form类中的内部类。 您不必在内部类中更改任何内容。只需遵循上述步骤。 所有的学分都应该归代码的原始设计者所有。我只是把它放在这里为任何人谁遇到同样的问题,需要一个好的和性感的答案 using Sy

是否可以使tabcontrol边框透明,或设置tabcontrol的颜色

  • Winforms

如果有人遇到同样的问题,以下是对我有效的答案

正如它所描述的, 创建一个NativeTabControl对象,并指定要删除其边框的tabControl的句柄。可以将此NativeTabControl类用作form类中的内部类。 您不必在内部类中更改任何内容。只需遵循上述步骤。 所有的学分都应该归代码的原始设计者所有。我只是把它放在这里为任何人谁遇到同样的问题,需要一个好的和性感的答案

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public class Form1
{


public Form1()
{
    // This call is required by the Windows Form Designer.
    InitializeComponent();

    // Add any initialization after the InitializeComponent() call.
    this.NativeTabControl1 = new NativeTabControl();
    this.NativeTabControl2 = new NativeTabControl();
    this.NativeTabControl1.AssignHandle(this.TabControl1.Handle);
    this.NativeTabControl2.AssignHandle(this.TabControl2.Handle);
}

private NativeTabControl NativeTabControl1;

private NativeTabControl NativeTabControl2;
private class NativeTabControl : NativeWindow
{

    protected override void WndProc(ref Message m)
    {
        if ((m.Msg == TCM_ADJUSTRECT)) {
            RECT rc = (RECT)m.GetLParam(typeof(RECT));
            //Adjust these values to suit, dependant upon Appearance
            rc.Left -= 3;
            rc.Right += 3;
            rc.Top -= 3;
            rc.Bottom += 3;
            Marshal.StructureToPtr(rc, m.LParam, true);
        }
        base.WndProc(ref m);
    }

    private const Int32 TCM_FIRST = 0x1300;
    private const Int32 TCM_ADJUSTRECT = (TCM_FIRST + 40);
    private struct RECT
    {
        public Int32 Left;
        public Int32 Top;
        public Int32 Right;
        public Int32 Bottom;
    }

}

}

您使用的是WinForms还是WPF?欢迎使用堆栈溢出!虽然这可以从理论上回答这个问题,但在这里包含答案的基本部分,并提供链接供参考。这是一段伟大的代码,感谢您的传播!以防万一,任何人都不喜欢这样一个事实,即没有顶部水平线将选项卡按钮与其下面的内容分隔开,只需简单地更改
rc.top-=3
rc.Top-=1将在上面放置一条顶部水平线。