C#去掉TabControl的外边框(非TabPage)
去除TabControl边框的解决方案,如果帮助到仁兄,您给点个赞呗
问题如下图:
话不多说,直接上代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace UI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.NativeTabControl1 = new NativeTabControl();
this.NativeTabControl2 = new NativeTabControl();
this.NativeTabControl1.AssignHandle(this.cTabControl1.Handle);
this.NativeTabControl2.AssignHandle(this.cTabControl1.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;
}
}
}
}
效果图
链接: 参考链接.