C#更改tabControl选项卡颜色的方法
作者:Microblue 发布时间:2022-09-07 19:30:14
标签:C#,tabControl选项卡
本文实例讲述了C#更改tabControl选项卡颜色的方法。分享给大家供大家参考,具体如下:
private void Form1_Load(object sender, EventArgs e)
{
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
}
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
if (e.Index == tabControl1.SelectedIndex)
e.Graphics.FillRectangle(Brushes.Red, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
else
e.Graphics.FillRectangle(Brushes.White, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
e.Graphics.DrawString(((TabControl)sender).TabPages[e.Index].Text,
System.Windows.Forms.SystemInformation.MenuFont, new SolidBrush(Color.Black), e.Bounds, sf);
}
1.在Form类的构造函数中添加下列语句:
this.tabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
2.实现下列函数:
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Font fntTab;
Brush bshBack;
Brush bshFore;
if ( e.Index == this.tabControl1.SelectedIndex)
{
fntTab = new Font(e.Font, FontStyle.Bold);
bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
bshFore = Brushes.Black;
}
else
{
fntTab = e.Font;
bshBack = new SolidBrush(Color.Blue );
bshFore = new SolidBrush(Color.Black);
}
string tabName = this.tabControl1.TabPages[e.Index].Text;
StringFormat sftTab = new StringFormat();
e.Graphics.FillRectangle(bshBack, e.Bounds);
Rectangle recTab = e.Bounds;
recTab = new Rectangle( recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
}
希望本文所述对大家C#程序设计有所帮助。


猜你喜欢
- 默认配置默认配置比较低,打开稍大点的项目就很容易卡掉,所以最好扩大一下内存。IntelliJ IDEA的VM配置IntelliJ IDEA2
- 我们很多时候会碰到这样的问题,使用多线程刷一个表的数据时需要多个线程不能重复提取数据,那么这个时候就需要使用到线程的排他锁了。在c#里面其实
- 用TabHost 来实现顶部选项卡,上代码:activity_main.xml<?xml version="1.0"
- 删除本地仓库未下载完成的缓存文件(删除像图片显示这样以.lastUpdated结尾的文件)执行mvn -v确保maven命令可以正常执行执行
- 在 C语言中,占位符是一种用于格式化输出的特殊字符,通常用于 printf() 等输出函数中,用于指定输出的格式和内容。在本文中,我们将详细
- 首先,建立图片与鼠标的对应关系。class MouseStyle{ [DllImport("user32.dll&qu
- 1.客户端代码public class UploadPicClient { public static void main(String[]
- Android 应用坐标系详解:
- 在有些开发场景,需要对 List 对象列表进行过滤处理,并将有用的数据存放到Map中。例如:告警对象,包含告警uuid(alarmUuid)
- 前言《模式策略的角色扮演游戏》游戏是自制的角色扮演游戏。选择两个角色,然后进行PK,可用来学习JAVA的接口,继承和多态。主要设计1.事先设
- 归并排序里运用到算法里很重要的一个思想——分治法:将原问题分解为几个规模较小但类似于原问题的子问题——《算法导论》。在每一层递归中都有3个步
- 前言本来没有计划这一篇文章的,只是在看完SpringBoot核心原理后,突然想到之前开发中遇到的MVC自动失效的问题,虽然网上有很多文章以及
- 在APP项目的开发过程中,经常会用到分享图片的功能,有时候还需要根据当前用户信息获取指定的分享图片,比如要求在用户分享图中显示用户名、Uid
- 前言本文的记录如何用CustomPaint、GestureDetector实现一个进度条控件。首先需要说明的是 flutter Materi
- 已经下过好几次了,现在还是忘了。就把过程直接放上面了。下次再换电脑就直接可以看。。。0.下载之前需要把JDK安装和配置好,点这里:https
- Kotlin 基础教程之异常概述在Kotlin-null的处理里提到的NPE,它就是一个异常。而,异常是程序运行过程中出现的错误。在Kotl
- 介绍在 C/C++ 中,程序员负责对象的创建和销毁。通常程序员会忽略无用对象的销毁。由于这种疏忽,在某些时候,为了创建新对象,可能没有足够的
- MyBatis-Plus 使用简单,内置通用 Mapper、通用 Service,仅仅通过少量配置,即可实现单表大部分 CRUD 操作。下面
- 事发地原默认的Feign是使用URLConnector进行通信的,当换为okhttp时,直接引入包及配置以下内容根本不生效,还是走原生的。f
- 一、简介Bottom Sheet是Design Support Library23.2 版本引入的一个类似于对话框的控件。 Bottom S