C# Windows 8.1应用程序-基于RichEditBox基线的超级下标
我有一个用于文本格式设置的面板,我必须进行上下标工作,但不能通过在RTF中插入\sub或\super来完成(RTF是我最终需要的)。 这是通过插入\sub设置上标的方式:C# Windows 8.1应用程序-基于RichEditBox基线的超级下标,c#,windows-8.1,rtf,subscript,richeditbox,C#,Windows 8.1,Rtf,Subscript,Richeditbox,我有一个用于文本格式设置的面板,我必须进行上下标工作,但不能通过在RTF中插入\sub或\super来完成(RTF是我最终需要的)。 这是通过插入\sub设置上标的方式: public void SetSuperscript() { ITextSelection selectedText = _textbox.Document.Selection; if (selectedText != null) { ITextCharacterFormat charF
public void SetSuperscript()
{
ITextSelection selectedText = _textbox.Document.Selection;
if (selectedText != null)
{
ITextCharacterFormat charFormatting = selectedText.CharacterFormat;
charFormatting.Superscript= FormatEffect.On;
selectedText.CharacterFormat = charFormatting;
}
}
现在我知道我也可以这样做:
public void SetSuperscript()
{
ITextSelection selectedText = _textbox.Document.Selection;
if (selectedText != null)
{
ITextCharacterFormat charFormatting = selectedText.CharacterFormat;
charFormatting.Size /= 2;
charFormatting.Position = charFormatting.Size;
selectedText.CharacterFormat = charFormatting;
}
}
而且效果也一样好。问题是在创建下标时:
public void SetSubscript()
{
ITextSelection selectedText = _textbox.Document.Selection;
if (selectedText != null)
{
ITextCharacterFormat charFormatting = selectedText.CharacterFormat;
charFormatting.Size /= 2;
charFormatting.Position = -charFormatting.Size;
selectedText.CharacterFormat = charFormatting;
}
}
上面的代码引发异常“值不在预期范围内”。这是由以下行引起的:
charFormatting.Position=-charFormatting.Size代码>
我在这里指定了一个负值(根据文档,这是正确的),因为我需要所选文本比正常文本低一半的高度。我做错了什么
丹尼尔