【问题标题】:Windows TabControl with Appearance=Buttons, getting wide margins on the right带有 Appearance=Buttons 的 Windows TabControl,在右侧获得较大的边距
【发布时间】:2014-02-26 15:23:58
【问题描述】:

我正在创建一个 Windows C#/.NET 应用程序,并且我正在尝试使用外观设置为按钮的 TabControl。我希望标签只有图像,没有文字。但是,我在每个按钮的右侧得到了一堆额外的填充,我想去掉它们:


我可以通过将字体大小减小到 1 来减小右边距,但它仍然比左侧宽几个像素,而且看起来有点笨拙。有没有更好的办法?

【问题讨论】:

  • 微软几乎没有做出任何努力来完成这项工作。 DrawMode.OwnerDrawFixed 可能是使其与 ItemSize 集和 SizeMode 设置为 Fixed 一起工作的唯一方法。
  • 图像只是左对齐,标签宽度不能太小,因此您最终会在图像右侧留出额外的空间。考虑更合适(更宽)的图像或所有者图。

标签: .net winforms tabcontrol


【解决方案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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 2017-02-23
    • 2013-11-03
    • 1970-01-01
    • 2021-02-11
    • 1970-01-01
    • 2018-02-19
    相关资源
    最近更新 更多