惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - 一场误会

Android 2.1 和 Android 4.4 工程目录超详细对比及详解 WinForm下CheckedListBox的数据绑定 完全卸载Oracle数据库的方法 SQL Server 安装错误服务无法启动,安装后没有SQL Server Management Studio管理器 开发人员一定要加入收藏夹的网站 也谈物联网 一位年轻女董事长的27条忠告 ASP.NET AJAX视频教程 文件上传带多种样式的进度条 工程项目四控六管一协调 用户自定义报表 甘特图、网络图控件 哈佛图书馆墙上的名训 C#文件上传下载 c#读写xml文件 - 一场误会 - 博客园 多表关联的update语句 VS2005调试问题解决方案集锦 - 一场误会 - 博客园 加密、解密.NET字符串 综采工作面设备接替计划管理系统
C#中添加文本框的上标及文字大小
一场误会 · 2013-01-23 · via 博客园 - 一场误会

最近在做一个项目时遇到需要在文本框中进行上下标的处理,单纯的文本控件TextBox满足不了这个功能,必须使用RichTextBox富文本控件来实现,具体效果如下:

未设置上标字体大小前:设置上标的字体大小后

具体的代码如下:

            this.richTextBox1.SelectedText = "mm";
            this.richTextBox1.SelectionFont = new Font("宋体", 8, FontStyle.Regular);
            this.richTextBox1.SelectionCharOffset = 3;   //位移的像素,正数为上移,负数为下移         
            this.richTextBox1.SelectedText = "2";

代码很简单,但是有个注意事项:this.richTextBox1.SelectionFont = new Font("宋体", 8, FontStyle.Regular);此行代码的位置很关键,如果在最后一行或者第一行显示,那么整个richTextBox1的字体大小都是8了,整个显示都很小;如果不设置,默认的字体是10号字体,显示的上面的那个2很大,效果不好如上图所示。