当TabControl的DrawMode为OwnerDrawFixed时,如何摆脱阴影?

时间:2019-08-01 02:24:12

标签: c# winforms tabcontrol

问题:
当TabControl的DrawMode为OwnerDrawFixed时,如何摆脱阴影?我希望具有与更改为OwnerDrawFixed之前相同的外观。

示例代码:

namespace Example {
  public partial class Form1 : Form {
    public Form1() {
      InitializeComponent();
      tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
      tabControl1.DrawItem += DrawItem_TabControl;
    }

    // I can only change this method.
    private void DrawItem_TabControl(object sender, DrawItemEventArgs e) {
      TabControl tabControl = sender as TabControl;
      TabPage tabPage = tabControl.TabPages[e.Index];
      Brush foreBrush = tabControl.Focused && tabControl.SelectedIndex == e.Index ? Brushes.Red : Brushes.Black;

      using (StringFormat format = new StringFormat()) {
        format.Alignment = StringAlignment.Center;
        format.LineAlignment = StringAlignment.Center;
        e.Graphics.DrawString(tabPage.Text, tabPage.Font, foreBrush, e.Bounds, format);
      }
    }
  }
}

左:忠诚,右:理想 reallity and ideal image

0 个答案:

没有答案