如何右对齐RichTextBox中的文本 [英] How to right align text in a RichTextBox
本文介绍了如何右对齐RichTextBox中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在运行时如何在RichTextBox中的一行中正确对齐文本的一部分?
How do I right align a portion of text in a line in a RichTextBox during runtime?
推荐答案
使用System.Windows.Forms.RichTextBox
,附加到Rtf
代码:string.Format("\qr {0}\par\", yourParagraphText);
您在变量yourParagraphText
中的文本将被添加为右对齐.或使用另一个属性SelectedRtf
插入中间.
是的,我知道愚蠢的RTF编码.我在写字板中输入了两个段落,然后保存了文件并查看其中的内容.
如果没有RTF行代码,则将属性System.Windows.Forms.RichTextBox.SelectionAlignment
与预选的段落一起使用.请参阅:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionalignment.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. windows.forms.horizontalalignment.aspx [ ^ ].
如果您不指出您使用的是Forms还是WPF,这对您不利.现在有关WPF:
至于System.Windows.Controls.RichTextBox
,您应该使用FlowDocument
进行所有工作,并使用构造函数RichTextBox(FlowDocument document)
获得RichTextBox
,请参见:
http://msdn.microsoft.com/en-us/library/ms597536.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. windows.documents.flowdocument.aspx [ ^ ].
—SA
WithSystem.Windows.Forms.RichTextBox
, append to theRtf
code:string.Format("\qr {0}\par\", yourParagraphText);
your text in the variableyourParagraphText
will be appended as right-aligned. Or use another property,SelectedRtf
, to insert in the middle.
Yes, stupid RTF coding, I know. I did it typing two paragraphs in WordPad, saving the file and looking at what''s inside.
Without RTF row code, use the propertySystem.Windows.Forms.RichTextBox.SelectionAlignment
with a preliminary selected paragraph. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionalignment.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.horizontalalignment.aspx[^].
This was not nice of you not to indicate if you work with Forms or WPF. Now about WPF:
As toSystem.Windows.Controls.RichTextBox
, you should do all the work withFlowDocument
instead, and get aRichTextBox
using the constructorRichTextBox(FlowDocument document)
, please see:
http://msdn.microsoft.com/en-us/library/ms597536.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.documents.flowdocument.aspx[^].
—SA
您可以进行选择并使用HorizontalAlignment:
RichTextBox.SelectionAlignment = HorizontalAlignment.Right;
问候
bejituharo
you can make a selection and use HorizontalAlignment:
RichTextBox.SelectionAlignment = HorizontalAlignment.Right;
regards
bejituharo
这篇关于如何右对齐RichTextBox中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文