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

推荐订阅源

博客园 - 【当耐特】
Help Net Security
Help Net Security
P
Proofpoint News Feed
J
Java Code Geeks
爱范儿
爱范儿
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
Google DeepMind News
Google DeepMind News
H
Help Net Security
G
Google Developers Blog
Jina AI
Jina AI
Vercel News
Vercel News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
Lohrmann on Cybersecurity
S
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
GbyAI
GbyAI
B
Blog
O
OpenAI News
博客园_首页
Cisco Talos Blog
Cisco Talos Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
腾讯CDC
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
Y
Y Combinator Blog
C
Cisco Blogs
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
AI
AI
W
WeLiveSecurity
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
Blog — PlanetScale
Blog — PlanetScale

博客园 - 一场误会

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很大,效果不好如上图所示。