|
-
October 9th, 2005, 04:03 AM
#1
How to add formatted text in RichTextBox control?
I have TabPages, Button and RichTextBox controls on my form. I like to format text and than add to RichTextBox which is placed on TabPage when I click on button.
Button1_Click event
RichTextBox1.Text(“This is my first line which I like to add as font size 24”)
Button2_Click event
RichTextBox1.AppendText(ControlChars.CrLf & “This is my second line which I like to add as font size 12”)
Please help to format text and than add to RichTextBox.
Ajay
-
October 10th, 2005, 07:46 AM
#2
Re: How to add formatted text in RichTextBox control?
 Originally Posted by Ajay Parmar
Button1_Click event
RichTextBox1.Text(“This is my first line which I like to add as font size 24”)
Button2_Click event
RichTextBox1.AppendText(ControlChars.CrLf & “This is my second line which I like to add as font size 12”)
Hello! I'm not sure I understand you properly..
Can't you do this instead ¿
Code:
RichTextBox1.SelectionFont = New Font("Tahoma", 24, FontStyle.Bold)
You could also use the Font Dialog:
Code:
Dim dlgFont As New FontDialog
If dlgFont.ShowDialog = DialogResult.OK Then Me.Font = dlgFont.Font
Last edited by HanneSThEGreaT; October 10th, 2005 at 07:57 AM.
-
October 10th, 2005, 01:30 PM
#3
Re: How to add formatted text in RichTextBox control?
Thanks Hannes,
i know command which your say but that is works on alrady entered text. that mean when you have text alrady in RichTextBox you can select it and format it. but i want that when i add my text first time at that time i format text first and than add.
i mean when i click on button i like to add one line of text with font size 24 and when i click on other button i like to add another line to that same rich text box with font size 12.
Thank you
Ajay
-
October 10th, 2005, 05:48 PM
#4
Re: How to add formatted text in RichTextBox control?
I realize I'm not going to be of much help. But unless you know the RTF format code chances are you're going to have to format the text after you put it in the RichTextBox.
One easy way to do this would be...
Code:
Dim MyStart as integer
Dim MyLength as integer
MyStart = RichTextBox.Text.Length 'Do this to get set the cursor location at the end of the RichTextBox.
MyLength = AppendText.Length
RichTextBox1.AppendText(ControlChars.CrLf & “This is my second line which I like to add as font size 12”)
RichTextBox1.SelectionStart = MyStart
RichTextBox1.SelectionLength = MyLength
RichTextBox1.SelectionFont = MyFont 'Whatever variable or font you want.
I think that should do the trick. As I know of know way to get pre-formated text into an RTB unless you're using cut and paste.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|