Hi Michael,
The introduction of RichTextBox class in MSDN may be a little sketchy. For
more information on how to use RichTextBox control in Windows Forms, you
could visit the following link.
http://msdn2.microsoft.com/en-us/library/aa467125.aspx
As for your first question, I am sorry that RichTextBox doesn't support
such a function at present. The Find method of the RichtTextBox can only
take a concrete string as its parameter. If you do need this function, I
recommend you to write a method to encapsulate the code for this function
(you could search the Internet for the arithmetic) and then call this
method whenever you want.
You have mentioned that you want to format some text when added. When a
text is added to a RichTextBox control, the SelectionStart property of the
RichTextBox is set to the end position of the added text. We could make use
of this feature to select the added text and then set the SelectionFont or
SelectionColor property of the RichTextBox.
The following is a sample.
this.richTextBoxPrintCtrl1.AppendText("abcde");
// set the SelectionStart property to the start position of the added text
this.richTextBoxPrintCtrl1.SelectionStart -= 5;
// set the SelectionLength property to the length of the added text
this.richTextBoxPrintCtrl1.SelectionLength = 5;
this.richTextBoxPrintCtrl1.SelectionFont = new Font("Times New Roman", 20);
this.richTextBoxPrintCtrl1.SelectionColor = Color.Blue;
As for your second question, could you tell me how you add a text in the
RichTextBox control? If we use the following code to add a text, the
previous format will be lost, because the Text property of the RichTextBox
control is re-assigned as as whole.
this.richTextBoxPrintCtrl1.Text += "abcde";
Instead, we could use the AppendText method of the RichTextBox control to
add a text.
Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.