好的,所以我需要将标签与c#中的标签页对齐。我尝试更改选项卡和页面的大小属性,但它没有帮助。它不会让我更改标签页的大小属性以匹配标签属性大小。我也试过改变标签本身的文字字体。可能有一些填充/边框/等。这使它不能对齐,我不确定。我也进入了标签控制属性"集合"并手动编辑边距/填充但无法使其工作。如何让它对齐?见下图。
以下是我的选项卡控件代码:
{
InitializeComponent();
tabControl.DrawItem += new DrawItemEventHandler(tabControl_DrawItem);
}
private void tabControl_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Brush txtBrush;
TabPage tabPage = tabControl.TabPages[e.Index];
Rectangle tabBounds = tabControl.GetTabRect(e.Index);
if (e.State == DrawItemState.Selected)
{
txtBrush = new SolidBrush(Color.White);
g.FillRectangle(Brushes.DarkGray, e.Bounds);
}
else
{
txtBrush = new System.Drawing.SolidBrush(e.ForeColor);
e.DrawBackground();
}
Font tabFont = new Font("Proggy", 15, FontStyle.Bold, GraphicsUnit.Pixel);
StringFormat strFlags = new StringFormat();
strFlags.Alignment = StringAlignment.Center;
strFlags.LineAlignment = StringAlignment.Center;
g.DrawString(tabPage.Text, tabFont, txtBrush, tabBounds, new StringFormat(strFlags));
}