Click to See Complete Forum and Search --> : How to add formatted text in RichTextBox control?
Ajay Parmar
October 9th, 2005, 04:03 AM
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
HanneSThEGreaT
October 10th, 2005, 07:46 AM
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! :wave: I'm not sure I understand you properly..
Can't you do this instead ¿
RichTextBox1.SelectionFont = New Font("Tahoma", 24, FontStyle.Bold)
You could also use the Font Dialog:
Dim dlgFont As New FontDialog
If dlgFont.ShowDialog = DialogResult.OK Then Me.Font = dlgFont.Font
Ajay Parmar
October 10th, 2005, 01:30 PM
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
LeviFiction
October 10th, 2005, 05:48 PM
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...
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.