C#环境中设置上标和下标(转)
在涉及到单位时,我们经常需要使用到上标和下标,在网上搜了一下,RICHTEXTBOX还是挺好用的,用法如下:
private void form_Load(object sender, EventArgs e)
{
Font richFont = new Font("宋体", 10);
richTextBox1.Font=richFont; //在c#中需要定义一FONT变量,在VB中可以不定义,直接设置FONT属性
richTextBox1.Text = "H2SO4";
OffsetRichText(richTextBox1,1,1,2);
OffsetRichText(richTextBox1, 4, 1, -2);
}
private void form_Load(object sender, EventArgs e)
{
Font richFont = new Font("宋体", 10);
richTextBox1.Font=richFont; //在c#中需要定义一FONT变量,在VB中可以不定义,直接设置FONT属性
richTextBox1.Text = "H2SO4";
OffsetRichText(richTextBox1,1,1,2);
OffsetRichText(richTextBox1, 4, 1, -2);
}
private void OffsetRichText(RichTextBox box, int iStart, int iLength, int iOffset)
{
box.SelectionStart = iStart;
box.SelectionLength = iLength;
Font richFont1 = new Font("宋体", box.Font.Size - System.Math.Abs(iOffset));
box.SelectionFont = richFont1;
box.SelectionCharOffset =iOffset;
box.SelectionStart = 0;
box.SelectionLength = 0;
}
欢迎访问SuperMap技术问答社区http://qa.supermap.com/
posted on 2009-08-17 15:17 Emily_Fly 阅读(2389) 评论(0) 编辑 收藏 举报