|
-
Aug 11th, 2011, 05:01 AM
#1
Thread Starter
Addicted Member
Format Text
Hi
This is going to be quite an explanation:
on the main form of my application, I have a Rich Text Box which is where the user will be entering information. The text is black.
then, i have a button which calls the dialogue "Notes"
A dialogue appears, with a rich text box.
the user should then be able to enter text into the box, click "OK", and the text entered into the Notes dialogue be inserted to the rich text box on the main form -- with the font colour "Red". The rest of the text in the main rich text box on the main form should remain black.
Help appreciated!
Many thanks,
M
-
Aug 12th, 2011, 05:20 AM
#2
Addicted Member
Re: Format Text
Hi this could be one solution:
When you create your dialog "Notes" in the constructor you can pass an instance of your main form
vb Code:
Dim notesForm as new Notes(me)
You then add teh text to your rich text box and click your ok button which will I presume close your Notes form and then using the main form object you can call a sub in your main form class that will add the new text to the main forms rich text box... The add text can look something like this...
vb Code:
Public Sub AddText(ByVal text As String)
Me.RichTextBox1.AppendText(text)' append to the existing text
Me.RichTextBox1.Select(RichTextBox1.Text.IndexOf(text), text.Length)'select the new text
Me.RichTextBox1.SelectionColor = Color.Red'make it red
End Sub
After doing this you will still have to return the rich text color back to black ... but I'll leave that to you
-
Aug 12th, 2011, 06:18 AM
#3
Re: Format Text
Something like this
Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim d As New Dialog1
Dim dr As DialogResult = d.ShowDialog
If dr = Windows.Forms.DialogResult.OK AndAlso d.RichTextBox1.TextLength > 0 Then
d.RichTextBox1.SelectAll()
d.RichTextBox1.SelectionColor = Color.Red
Me.RichTextBox1.SelectedRtf = d.RichTextBox1.SelectedRtf
End If
End Sub
Tags for this Thread
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
|