在标签页顶部绘制突出显示

发布于 2024-11-19 23:17:06 字数 243 浏览 3 评论 0原文

我在 Windows 窗体应用程序(C#)中使用 TabControl

我想使用 hightlightcolor 在选项卡页标题的顶部绘制突出显示。

http://img4up.com/up2/83871411772596923665.jpg

谢谢

i am using TabControl in my windows form application (c#)

and

i want draw the Highlight over the top of the tabpage headers using hightlightcolor.

http://img4up.com/up2/83871411772596923665.jpg

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉鱼一梦 2024-11-26 23:17:06

我希望这会对您有所帮助。只需在选项卡控件的 OnDrawItem 事件中应用下面提到的代码即可

if (e.Index == SelectedIndex)
{
    Rectangle rect = new Rectangle(e.Bounds.X + 4, e.Bounds.Y, e.Bounds.Width - 6, e.Bounds.Height);
    backColorBrush = new SolidBrush(Color.CornflowerBlue);
    e.Graphics.FillRectangle(backColorBrush, rect);
    string tabName = this.TabPages[e.Index].Text;

    TabPages[e.Index].BackColor = Color.AliceBlue;
    TabPages[e.Index].BorderStyle = BorderStyle.None;

    TabPages[e.Index].UseVisualStyleBackColor = false;
    TabPages[e.Index].RightToLeft = RightToLeft.No;
    myFormat.Alignment = StringAlignment.Near;
    myFont = new Font(e.Font, FontStyle.Bold);
    RectangleF r1 = new RectangleF(e.Bounds.X + 1, e.Bounds.Y + 4, e.Bounds.Width, e.Bounds.Height - 4);
    foreColorBrush = new System.Drawing.SolidBrush(Color.Black);
    e.Graphics.DrawString(tabName, myFont, foreColorBrush, r1, myFormat);
    // e.Graphics.DrawImage(img, new Point(rect.X + (GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y));
}
else
{
    myFont = new Font(e.Font, FontStyle.Bold);
    backColorBrush = new System.Drawing.SolidBrush(Color.CadetBlue);
    foreColorBrush = new System.Drawing.SolidBrush(Color.Black);

    TabPages[e.Index].BackColor = Color.AliceBlue;
    string tabName = TabPages[e.Index].Text;

    Rectangle rect = new Rectangle(e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height + 1);
    myFormat.Alignment = StringAlignment.Near;
    e.Graphics.FillRectangle(backColorBrush, rect);
    RectangleF r1 = new RectangleF(e.Bounds.X, e.Bounds.Y + 4, e.Bounds.Width, e.Bounds.Height - 4);
    e.Graphics.DrawString(tabName, myFont, foreColorBrush, r1, myFormat);
    //e.Graphics.DrawImage(img, new Point(rect.X + (GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y));
}
myFormat.Dispose();
myFont.Dispose();
backColorBrush.Dispose();
foreColorBrush.Dispose();

I hope this will help you. Just apply this below mentioned code in OnDrawItem Event of Tab Control

if (e.Index == SelectedIndex)
{
    Rectangle rect = new Rectangle(e.Bounds.X + 4, e.Bounds.Y, e.Bounds.Width - 6, e.Bounds.Height);
    backColorBrush = new SolidBrush(Color.CornflowerBlue);
    e.Graphics.FillRectangle(backColorBrush, rect);
    string tabName = this.TabPages[e.Index].Text;

    TabPages[e.Index].BackColor = Color.AliceBlue;
    TabPages[e.Index].BorderStyle = BorderStyle.None;

    TabPages[e.Index].UseVisualStyleBackColor = false;
    TabPages[e.Index].RightToLeft = RightToLeft.No;
    myFormat.Alignment = StringAlignment.Near;
    myFont = new Font(e.Font, FontStyle.Bold);
    RectangleF r1 = new RectangleF(e.Bounds.X + 1, e.Bounds.Y + 4, e.Bounds.Width, e.Bounds.Height - 4);
    foreColorBrush = new System.Drawing.SolidBrush(Color.Black);
    e.Graphics.DrawString(tabName, myFont, foreColorBrush, r1, myFormat);
    // e.Graphics.DrawImage(img, new Point(rect.X + (GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y));
}
else
{
    myFont = new Font(e.Font, FontStyle.Bold);
    backColorBrush = new System.Drawing.SolidBrush(Color.CadetBlue);
    foreColorBrush = new System.Drawing.SolidBrush(Color.Black);

    TabPages[e.Index].BackColor = Color.AliceBlue;
    string tabName = TabPages[e.Index].Text;

    Rectangle rect = new Rectangle(e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height + 1);
    myFormat.Alignment = StringAlignment.Near;
    e.Graphics.FillRectangle(backColorBrush, rect);
    RectangleF r1 = new RectangleF(e.Bounds.X, e.Bounds.Y + 4, e.Bounds.Width, e.Bounds.Height - 4);
    e.Graphics.DrawString(tabName, myFont, foreColorBrush, r1, myFormat);
    //e.Graphics.DrawImage(img, new Point(rect.X + (GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y));
}
myFormat.Dispose();
myFont.Dispose();
backColorBrush.Dispose();
foreColorBrush.Dispose();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文