Write text with coefficient like C₁, C₂, C₃ on label

孤街浪徒 提交于 2019-12-10 18:05:03

问题


I have to write text with coefficient value like C1, C2, C3 on label text, so please tell me how can i write ???

thanks Shashi Jaiswal


回答1:


You need a font that comes with glyphs for Unicode codepoints U+2080 to U+2089:

label1.Font = new Font("DejaVu Sans", 10);
label1.Text = "C₁";  // or "C\u2081"

(assuming WinForms)




回答2:


In WinForms you need to emulate that with a RichTextBox

// Appearance as a label
var subscriptFont = new System.Drawing.Font(
                        richTextBox1.Font.FontFamily, 
                        richTextBox1.Font.Size - 2);
richTextBox1.BackColor = System.Drawing.SystemColors.Control;
richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
richTextBox1.ReadOnly = true;
richTextBox1.Text = "C1, C2, C3";
// subscript 1
richTextBox1.Select(1, 1);
richTextBox1.SelectionCharOffset = -3;
richTextBox1.SelectionFont = subscriptFont;
// subscript 2
richTextBox1.Select(5, 1);
richTextBox1.SelectionCharOffset = -3;
richTextBox1.SelectionFont =subscriptFont;
// subscript 3
richTextBox1.Select(9, 1);
richTextBox1.SelectionCharOffset = -3;
richTextBox1.SelectionFont = subscriptFont;
subscriptFont.Dispose();



回答3:


You could try using a different font that haves subindexes...




回答4:


You can't. Plain and simple.

(But you could use two labels, positioned and sized accordingly, or use a label that supports complex markup... Or use UTF-8, which allows them...)

But a stock C# Winforms project? Nah.



来源:https://stackoverflow.com/questions/5220046/write-text-with-coefficient-like-c%e2%82%81-c%e2%82%82-c%e2%82%83-on-label

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!