C# 如何在Visual C中显示下标?

C# 如何在Visual C中显示下标?,c#,subscript,C#,Subscript,我正在为我的a级计算项目制作一个弹丸运动模拟程序,我需要使用带有下标的物理符号。我不知道如何在标签或富文本框中使用它。 有谁能给我一些帮助/代码来实现这一点吗?您需要在中使用属性来实现这一点 对于下标,将数字设为负数,如下所示: richTextBox1.SelectionCharOffset = -10; SelectioncharOffset不是您的最佳选择。最好操作rtf并添加下标标签 //This allows you to reselect the text in the rtb a

我正在为我的a级计算项目制作一个弹丸运动模拟程序,我需要使用带有下标的物理符号。我不知道如何在标签或富文本框中使用它。 有谁能给我一些帮助/代码来实现这一点吗?

您需要在中使用属性来实现这一点

对于下标,将数字设为负数,如下所示:

richTextBox1.SelectionCharOffset = -10;

SelectioncharOffset不是您的最佳选择。最好操作rtf并添加下标标签

//This allows you to reselect the text in the rtb after formatting
            int SelectionStart = richTextBox1.SelectionStart;
            int SelectionLength = richTextBox1.SelectionLength;

            string selectedRtf = richTextBox1.SelectedRtf;
            int Start;
            int End;
            string pre;
            string Mid;
            string post;

            //remove superscript from selected text
            Start = selectedRtf.IndexOf("\\super");
            while (Start != -1)
            {
                pre = selectedRtf.Substring(0, Start);
                post = selectedRtf.Substring(Start + 6, selectedRtf.Length - (Start + 6));
                selectedRtf = pre.Trim() + post.Trim();
                Start = selectedRtf.IndexOf("\\super");
            }

            //if selected text does not contain subscript
            if (selectedRtf.IndexOf("\\sub") == -1 && selectedRtf.IndexOf("\\nosupersub") == -1)
            {
                Start = selectedRtf.IndexOf("}}") + 2;
                End = selectedRtf.IndexOf("}", Start);
                pre = selectedRtf.Substring(0, Start);
                Mid = selectedRtf.Substring(Start, End - Start);
                post = selectedRtf.Substring(End, selectedRtf.Length - End);
                selectedRtf = pre + "\\sub" + Mid + "\\nosupersub" + post;
                goto Clean;
            }
            //if selected text contains subscript
            if (selectedRtf.IndexOf("\\sub") > 0)
            {
                Start = selectedRtf.IndexOf("\\sub");
                while (Start != -1)
                {
                    pre = selectedRtf.Substring(0, Start);
                    post = selectedRtf.Substring(Start + 4, selectedRtf.Length - (Start + 4));
                    selectedRtf = pre.Trim() + post.Trim();
                    Start = selectedRtf.IndexOf("\\sub");

                }
                goto Clean;
            }


        Clean:
            richTextBox1.SelectedRtf = selectedRtf;
            richTextBox1.Focus();
            richTextBox1.SelectionStart = SelectionStart;
            richTextBox1.SelectionLength = SelectionLength;

那是上标。使用正数表示
选择字符偏移量
。V位为正常值,垂直位为下标。有没有办法选择订阅的部件?请阅读,这里有一个详细的示例。如果您是订阅该文本的人,您应该已经将其选中。欢迎使用StackOverflow:)因为您是新用户,并且是第一次发布,所以请谨慎地了解其工作原理。向我们展示您在理解您的问题方面的一些努力。:)你试过什么?研究?你的大学/学院没有教你如何进行研究吗?听着,这并没有让人觉得粗鲁,但看到“有人能给我帮助/代码来实现这一点吗?”这句俏皮话表明零努力,即懒惰…:)