当我将对齐设置为左侧时,C#tabcontrol字体错误
我对当我将对齐设置为左侧时,C#tabcontrol字体错误,c#,winforms,fonts,tabcontrol,C#,Winforms,Fonts,Tabcontrol,我对选项卡控件的字体有问题。 我将对齐设置为左对齐,并使用以下代码设置字体: private void tabControl1_DrawItem(Object sender, System.Windows.Forms.DrawItemEventArgs e) { Graphics g = e.Graphics; Brush _textBrush; // Get the item from the colle
选项卡控件的字体有问题。
我将对齐设置为左对齐,并使用以下代码设置字体:
private void tabControl1_DrawItem(Object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Brush _textBrush;
// Get the item from the collection.
TabPage _tabPage = tabControl1.TabPages[e.Index];
// Get the real bounds for the tab rectangle.
Rectangle _tabBounds = tabControl1.GetTabRect(e.Index);
if (e.State == DrawItemState.Selected) {
// Draw a different background color, and don't paint a focus rectangle.
_textBrush = new SolidBrush(Color.Black);
g.FillRectangle(Brushes.LightSkyBlue, e.Bounds);
}
else {
_textBrush = new System.Drawing.SolidBrush(e.ForeColor);
e.DrawBackground();
}
// Use our own font.
Font _tabFont = new Font("Calibri", (float)11.0, FontStyle.Regular, GraphicsUnit.Pixel);
// Draw string. Left the text.
StringFormat _stringFlags = new StringFormat();
_stringFlags.Alignment = StringAlignment.Near;
_stringFlags.LineAlignment = StringAlignment.Center;
g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags));
}
我将字体设置为“Calibri”(float)11.0,但tabcontrol中的文本较小。请参阅以下资料:
如何设置正确的字体
非常感谢你的帮助
Eric出于某种原因,你要求11像素,这就是你得到的。错误位于椅子和键盘之间?出于某种原因,您要求11像素,这就是您得到的。错误位于椅子和键盘之间?