-
Jun 7th, 2019, 10:02 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Keep Formatting From One RichTextbox To Another RichTextBox?
Working on a chat/messaging program where I have a richtextbox and I have formatting options like bold, underline, italic, font colors and so on but I need to keep the formatting upon pressing the command button that sends the formatted text to the second richtextbox window.. it is not working the way I have it now:
Code:
RichTextBox1.AppendText(RichTextBox2.Text & vbCrLf)
-
Jun 8th, 2019, 01:36 AM
#2
Re: Keep Formatting From One RichTextbox To Another RichTextBox?
vb.net Code:
'Position the caret at the end of the destination control.
RichTextBox1.SelectionStart = RichTextBox1.TextLength
'Get the formatted text from the source and insert it into the destination.
RichTextBox1.SelectedRtf = RichTextBox2.Rtf
'Append a line break.
RichTextBox1.AppendText(ControlChars.Lf)
You have to work with the formatted text, not the plain text, and you have to insert formatted text at the end rather than appending it.
Also note that a RichTextBox uses line feeds alone as line breaks, rather than carriage return and line feed pairs. I've never looked into it but I assume that that is part of the RTF specification. The control does understand both but it's best to stick with the standard.
Last edited by jmcilhinney; Jun 8th, 2019 at 01:42 AM.
-
Jun 8th, 2019, 12:58 PM
#3
Thread Starter
Hyperactive Member
Re: Keep Formatting From One RichTextbox To Another RichTextBox?
No it is not working at all for some reason, no text is being transferred to the second richtextbox..
You have to work with the formatted text, not the plain text, and you have to insert formatted text at the end rather than appending it.
Also note that a RichTextBox uses line feeds alone as line breaks, rather than carriage return and line feed pairs. I've never looked into it but I assume that that is part of the RTF specification. The control does understand both but it's best to stick with the standard.
Thanks ok I need to read up on all kinds of stuff just started buying some books.
-
Jun 8th, 2019, 03:55 PM
#4
Thread Starter
Hyperactive Member
Re: Keep Formatting From One RichTextbox To Another RichTextBox?
ok for some reason the text is not showing at all when I click the command button, it is only adding a blank space..
This is what I am using in the button:
Code:
'Position the caret at the end of the destination control.
ChatWindow.SelectionStart = ChatWindow.TextLength
'Get the formatted text from the source and insert it into the destination.
ChatEdit.SelectedRtf = ChatWindow.SelectedRtf
'Append a line break.
ChatWindow.AppendText(ControlChars.Lf)
-
Jun 8th, 2019, 04:11 PM
#5
Re: Keep Formatting From One RichTextbox To Another RichTextBox?
Here's the documentation on the RichTextBox Class. Take a look through the methods and properties.
https://docs.microsoft.com/en-us/dot...rk-4.8#methods
-
Jun 8th, 2019, 09:01 PM
#6
Re: Keep Formatting From One RichTextbox To Another RichTextBox?
You're just supplying the text start. You need to supply the text length too, before using SelectedRtf
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 8th, 2019, 09:16 PM
#7
Thread Starter
Hyperactive Member
Re: Keep Formatting From One RichTextbox To Another RichTextBox?
I am not exactly sure what you mean, the example says textlength before the selectedrtf. I just need it to use all the formatted text in the ChatEdit (RichTextBox) and send it formatted to the ChatWindow (RichTextBox)
-
Jun 8th, 2019, 09:17 PM
#8
Re: Keep Formatting From One RichTextbox To Another RichTextBox?
Originally Posted by DreamWarrior77
ok for some reason the text is not showing at all when I click the command button, it is only adding a blank space..
This is what I am using in the button:
Code:
'Position the caret at the end of the destination control.
ChatWindow.SelectionStart = ChatWindow.TextLength
'Get the formatted text from the source and insert it into the destination.
ChatEdit.SelectedRtf = ChatWindow.SelectedRtf
'Append a line break.
ChatWindow.AppendText(ControlChars.Lf)
Goodness me. Read my code properly. I even explain it in the comments! Here's my code:
Code:
'Position the caret at the end of the destination control.
RichTextBox1.SelectionStart = RichTextBox1.TextLength
'Get the formatted text from the source and insert it into the destination.
RichTextBox1.SelectedRtf = RichTextBox2.Rtf
'Append a line break.
RichTextBox1.AppendText(ControlChars.Lf)
and here's your code:
Code:
'Position the caret at the end of the destination control.
ChatWindow.SelectionStart = ChatWindow.TextLength
'Get the formatted text from the source and insert it into the destination.
ChatEdit.SelectedRtf = ChatWindow.SelectedRtf
'Append a line break.
ChatWindow.AppendText(ControlChars.Lf)
Spot the difference. In my code, RichTextBox1 is the destination and RichTextBox2 is the source. Which of your controls is the destination and which is the source? You're inserting text FROM ChatWindow TO ChatEdit, which I suspect is backwards. If it's not backwards then why are you using ChatWindow everywhere else, including appending the line break?
Also, why are you using SelectedRtf twice when in the middle line? That is only going to work if you have first selected some text in the source and you will then insert only that selected part of the text into the destination. If you want to get all the text from the source then you should be using its Rtf property, as I do in my code, rather than the SelectedRtf property. That's what .paul. was referring to, I would think. If you really do only want to get part of the text from the source then you need to set SelectionStart AND SelectionLength in order to do so. I doubt that's what you're actually trying to achieve though.
-
Jun 8th, 2019, 09:51 PM
#9
Thread Starter
Hyperactive Member
Re: Keep Formatting From One RichTextbox To Another RichTextBox?
I'm sorry I get confused so easily a lot of times. It seems that I got mixed up with my names of the richtextboxes that I had and then to make matters worse when that did not work since I mixed up the richtextbox names.. I accidentally changed the .rtf to.selectedrtf.. big mess on my part due to confusion.
Anyways Thanks it was syntax errors on my part, it works just fine now.
-
Jun 8th, 2019, 09:54 PM
#10
Re: [RESOLVED] Keep Formatting From One RichTextbox To Another RichTextBox?
All's well that ends well.
-
Jun 8th, 2019, 09:59 PM
#11
Thread Starter
Hyperactive Member
Re: [RESOLVED] Keep Formatting From One RichTextbox To Another RichTextBox?
Awesome Yes, I am very happy this works now.. I was hoping to get this working for 2 days. Just putting one foot in front of the other getting this project done one step at a time.
Thanks for all your help. Got my book on network programming today.
-
Jun 8th, 2019, 10:06 PM
#12
Re: [RESOLVED] Keep Formatting From One RichTextbox To Another RichTextBox?
Originally Posted by DreamWarrior77
Got my book on network programming today.
Get back to us when you get to the chapter about chanting in dead languages and sacrificing chickens. That may be more applicable to network engineering but anything to do with networks is always fun.
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
|