首页 新闻 会员 周边

关于winform 的标签页控件tabControl设置选项卡垂直左停靠重绘后,标签页被隐藏不显示问题?

0
悬赏园豆:20 [待解决问题]

protected override void OnDrawItem(DrawItemEventArgs e)
{
TabPage tabPage = this.TabPages[e.Index];
tabPage.UseVisualStyleBackColor = true;
Graphics g = e.Graphics;
Brush backtabcontrol;//整个tab控件背景色
Brush backbrush;//标签页背景色
Brush textBrush;//标签字体颜色
Font tabFont;//标签字体
if (e.State == DrawItemState.Selected)
{
textBrush = new SolidBrush(Color.FromArgb(255, 29, 168, 255));
}
else
{
textBrush = new SolidBrush(e.ForeColor);
}
//绘制整个tab控件背景
backtabcontrol = new SolidBrush(Color.FromArgb(255, 252, 252, 252));
g.FillRectangle(backtabcontrol, this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Size.Width, this.ClientRectangle.Height);
//绘制激活标签页标题区域的背景
//tabPage.BackColor =Color.FromArgb(255, 250, 250, 250);
Rectangle backrect = this.GetTabRect(e.Index);//标签页区域
backbrush = new SolidBrush(Color.FromArgb(255, 250, 250, 250));
g.FillRectangle(backbrush, backrect);
//绘制标签标题字体
tabFont = new Font("微软雅黑", 13, FontStyle.Bold, GraphicsUnit.Pixel);
StringFormat strFlags = new StringFormat(StringFormatFlags.DisplayFormatControl);
strFlags.Alignment = StringAlignment.Center;
strFlags.LineAlignment = StringAlignment.Center;
g.DrawString(tabPage.Text, tabFont, textBrush, backrect, strFlags);
tabPage.ToolTipText = tabPage.Text;
backtabcontrol.Dispose();
backbrush.Dispose();
tabFont.Dispose();
textBrush.Dispose();
base.OnDrawItem(e);
}

狂奔的桥的主页 狂奔的桥 | 初学一级 | 园豆:184
提问于:2021-06-28 11:56
< >
分享
所有回答(1)
0

protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
TabPage tabPage = this.TabPages[e.Index];
Graphics g = e.Graphics;
Brush tabBackColor;//整个tab控件背景色
Brush tabTitleBackColor;//标签页标题区域背景色
Brush textColor;//标签字体颜色
//绘制整个tab控件背景,继承父控件背景色
tabBackColor = new SolidBrush(this.Parent.BackColor);
g.FillRectangle(tabBackColor, this.ClientRectangle);
tabBackColor.Dispose();
//文本显示方式
StringFormat textFormat = new StringFormat(StringFormatFlags.DisplayFormatControl);
textFormat.Alignment = StringAlignment.Center;
textFormat.LineAlignment = StringAlignment.Center;
for(int i = 0; i < this.TabPages.Count; i++)
{
//标签页区域
Rectangle tabTitleRect = this.GetTabRect(i);
if (e.State== DrawItemState.Selected&&tabPage==this.TabPages[i])
{
tabTitleBackColor = new SolidBrush(Color.White);
textColor = new SolidBrush(Color.FromArgb(255, 29, 168, 255));
}
else
{
tabTitleBackColor = new SolidBrush(this.TabPages[i].BackColor);
textColor = new SolidBrush(this.TabPages[i].ForeColor);
}
tabTitleBackColor = new SolidBrush(Color.Transparent);
//绘制激活标签页标题区域的背景
g.FillRectangle(tabTitleBackColor, tabTitleRect);
tabTitleBackColor.Dispose();
//绘制标签标题字体
g.DrawString(this.TabPages[i].Text, this.TabPages[i].Font, textColor, tabTitleRect, textFormat);
this.TabPages[i].ToolTipText = this.TabPages[i].Text;
textColor.Dispose();
}
}

狂奔的桥 | 园豆:184 (初学一级) | 2021-06-29 08:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册