C# tabcontrol中的侧对齐选项卡
因为我是C初学者,我不知道在我的情况下该怎么办。我想要一个侧面对齐的选项卡控件,因此我发现: 现在,选项卡页名称根本不显示。我怎么画?我希望有人能帮助我。DrawItem方法:C# tabcontrol中的侧对齐选项卡,c#,winforms,draw,tabcontrol,C#,Winforms,Draw,Tabcontrol,因为我是C初学者,我不知道在我的情况下该怎么办。我想要一个侧面对齐的选项卡控件,因此我发现: 现在,选项卡页名称根本不显示。我怎么画?我希望有人能帮助我。DrawItem方法: private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) { Graphics g = e.Graphics; Brush _textBrush; // Get the item
private void tabControl1_DrawItem(object sender, 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.Red);
g.FillRectangle(Brushes.Gray, e.Bounds);
}
else
{
_textBrush = new System.Drawing.SolidBrush(e.ForeColor);
e.DrawBackground();
}
// Use our own font.
Font _tabFont = new Font("Arial", (float)10.0, FontStyle.Bold, GraphicsUnit.Pixel);
// Draw string. Center the text.
StringFormat _stringFlags = new StringFormat();
_stringFlags.Alignment = StringAlignment.Center;
_stringFlags.LineAlignment = StringAlignment.Center;
g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags));
}
您当前的代码中有g.DrawString部分吗?有,但我不知道如何正确使用。那是我的问题。对不起,如果这是一个愚蠢的问题,但我仍然在学习语言。没关系,我们都去过那里!您能编辑您的问题以包括您当前的DrawItem方法吗?好的,完成!现在已编辑。文本是否为空?