带有Appearance = Buttons的Windows TabControl,在右侧获得宽边距

时间:2013-08-01 16:04:42

标签: .net winforms tabcontrol

我正在创建一个Windows C#/。NET应用程序,我正在尝试使用TabControl并将Appearance设置为Buttons。我希望标签只有图像,没有文字。但是,我在每个按钮的右侧都有一堆额外的填充,我想摆脱它:

enter image description here
我可以通过将字体大小减小到1来减少右边距,但它仍然比左侧宽几个像素,并且它看起来有点笨拙。还有更好的方法吗?

1 个答案:

答案 0 :(得分:1)

试试这个

public frmForm()
{
     InitializeComponent();
     tabControl1.Appearance = TabAppearance.Buttons;
     tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
     tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem);
}

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
    //Load the image
    Image img = Image.FromFile(String.Format("{0}\\{1}.jpg",Application.StartupPath,tabControl1.TabPages[e.Index].Name));
    //Resize image
    img = new Bitmap(img, e.Bounds.Size);
    //Draw on Tab Button
    e.Graphics.DrawImage(img, e.Bounds.Location);
}

enter image description here