Write text with coefficient like C₁, C₂, C₃ on label
I have to write text with coefficient value like C1, C2, C3 on label text, so please tell me how can i write ???
t开发者_Go百科hanks Shashi Jaiswal
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)
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();
You could try using a different font that haves subindexes...
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.
精彩评论