-
Nov 29th, 2020, 09:00 PM
#1
Thread Starter
Hyperactive Member
Interpret Raw RTF Markup Text To RichTextBox?
How can I make my RichTextBox be able to read/interpret the raw RTF Markup/Text?
I would like to be able to enter the raw RTF markup text from one TextBox/RichTextBox and then have the other RichTextBox interpret it.
-
Nov 29th, 2020, 10:16 PM
#2
Re: Interpret Raw RTF Markup Text To RichTextBox?
Think it through, if the user enters text into a TextBox then you get that text from the Text property of the control. If you want text to appear in the TextBox using code then what do you do? You assign the appropriate String to the Text property, right?
Now, you already know that if you want to get the RTF markup for what you see in a RichTextBox control then you get the value of the Rtf property. If you have some RTF code and you want it represented in a RichTextBox, what do you suppose you should do with it?
-
Nov 29th, 2020, 10:56 PM
#3
Thread Starter
Hyperactive Member
Re: Interpret Raw RTF Markup Text To RichTextBox?
trying to make sense of it but it is not working.. trying:
Code:
ChatWindow.SelectionStart = ChatWindow.TextLength
ChatWindow.SelectedRtf = ChatEdit.Rtf
ChatWindow.AppendText(ControlChars.Lf)
ChatWindow.ScrollToCaret()
I was using this in a button to just send the formatted RTF text to the chatwindow but it will not take the raw RTF markup and interpret it if I place it in the chatedit box and press the command button..
Last edited by DreamWarrior77; Nov 29th, 2020 at 11:18 PM.
-
Nov 29th, 2020, 11:43 PM
#4
Re: Interpret Raw RTF Markup Text To RichTextBox?
This is an example of why you need to ALWAYS provide a FULL and CLEAR explanation of the problem. You didn't previously explain that you wanted to append to existing data already in the control. If you think about this in HTML terms then you would be copying the root <html> tag from the source control into the destination control and thus end up with two <html> tags, possibly nested, which is obviously invalid. What you're doing is akin to that but with RTF markup rather than HTML. You're going to have to pick out just the part that you need from the source control and insert it in the correct location in the destination control to produce valid RTF in the form you want.
I haven't tested but the easiest way to achieve this might actually be using copy and paste:
vb.net Code:
ChatWindow.SelectionStart = ChatWindow.TextLength
ChatEdit.SelectAll()
ChatEdit.Copy()
ChatWindow.Paste(DataFormats.GetFormat(DataFormats.Rtf))
Specifying the format when pasting may not be required.
-
Nov 29th, 2020, 11:57 PM
#5
Thread Starter
Hyperactive Member
Re: Interpret Raw RTF Markup Text To RichTextBox?
ok well here is the issue, I will need to have chat users be able to use the raw RTF codes and be able for them to paste them in the chatedit box
and then send them to the main chatroom window (richtextbox)
it will work kind of like AOL chat used to where we used to be able to place HTML code instead of RTF code in the edit/send text box but it is the same idea with this..
same type of thing is what I am trying for. I need to be clearer in future posts, I am sorry my brain has not been working so good and I am not just saying that..
I am coming off of years of horrible meds that have hurt my brain very much.
I am thankful to even be alive..
Just trying to hang on and hope to recover day by day, that is all I can do.. and Thank You for all your help by the way.
Visual Basic is one of the only things keeping me going in my life and I truly do appreciate everything you and everyone else on the forums have been able to help me with.
Thanks to anyone else who has tried to help me out with things.
-
Nov 30th, 2020, 02:22 AM
#6
Re: Interpret Raw RTF Markup Text To RichTextBox?
I just tested this and it seemed to work for me:
vb.net Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Bold)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Italic)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
RichTextBox1.SelectionColor = Color.Red
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
RichTextBox1.SelectAll()
RichTextBox1.Cut()
RichTextBox2.SelectionStart = RichTextBox2.TextLength
RichTextBox2.Paste()
RichTextBox2.AppendText(ControlChars.Lf)
End Sub
-
Nov 30th, 2020, 10:39 AM
#7
Thread Starter
Hyperactive Member
Re: Interpret Raw RTF Markup Text To RichTextBox?
I don't think your are understanding exactly what I am mean so I am including an image to help..
The image came out small on here, not sure why it is bigger on my computer for some reason..
anyway to make the uploaded image larger?
tried manage upload utility did not see any option, tried to re-upload it but it uploads it smaller for some reason.
The chatedit box is where the user edits their richtext on the fly and can send it to the chatwindow
it is showing the raw RTF markup code on the right in the textbox. This is for my testing purposes for now but
I can send the edited richtext from the chatedit to the chatwindow but not the raw RTF code from the textbox on the right side which
is what I am currently trying to do.
When users are not signed in I want to be able to have an Offline Rich Text Editor where they can save RTF messages for later in Raw RTF markup code and then send them
via the ChatEdit by placing the Raw RTF Markup in the ChatEdit Box and be able to press the button to send it to the Chatrooms ChatWindow and have it interpreted.
Last edited by DreamWarrior77; Nov 30th, 2020 at 01:28 PM.
-
Nov 30th, 2020, 11:02 AM
#8
Re: Interpret Raw RTF Markup Text To RichTextBox?
The link to the attachment comes out invalid for some reason. If you're doing a screen shot, don't do the whole screen, just capture the part that's relevant. rThe forum does stuff to large images. Also add it to your post as an image, not an attachment/file. Then it will display inline where we can all see it.
-tg
-
Nov 30th, 2020, 01:29 PM
#9
Thread Starter
Hyperactive Member
Re: Interpret Raw RTF Markup Text To RichTextBox?
is there anyway to upload/display it at the original file size?
still too small to really see it..
well if you can try to make it out I am trying to take the raw code on the right side, and copy and paste it in the lower chatedit box and then press command button to send to chatwindow to interpret the raw RTF data..
-
Nov 30th, 2020, 02:49 PM
#10
Re: Interpret Raw RTF Markup Text To RichTextBox?
Might want to take a look at this thread:
https://stackoverflow.com/questions/...ox-win-c-sharp
Specifically, the last comment:
"Sometimes I get around this in cases where I must do this by creating a hidden Rich Text control, stuff its Rtf property with the full RTF text to insert, invoke its SelectAll method to select all the text I want to insert, and then plug that RTB's SelectedRtf property to the target SelectedRtf property."
Good luck.
-
Nov 30th, 2020, 06:47 PM
#11
Thread Starter
Hyperactive Member
Re: Interpret Raw RTF Markup Text To RichTextBox?
Thanks Optionbase1 it was easier than that.
All I had to do was this:
Code:
ChatWindow.SelectedRtf = "Raw RTF Data Here"
Now it is time for tinkering with it, thanks this should keep me busy
One issue now though is how can I tell if the user has edited text or entered the raw RTF markup code?
Because what I want to be able to do is have them be able to do both, by both I mean edit text right in the edit box OR take saved RTF markup and paste in into the edit box and send it.
I want for the user to be able to do both in the chatedit box and press the command button and have both work no matter which they choose to do..
Last edited by DreamWarrior77; Nov 30th, 2020 at 06:50 PM.
-
Nov 30th, 2020, 06:49 PM
#12
Re: Interpret Raw RTF Markup Text To RichTextBox?
In post #7, is that ChatEdit on the right? If you're actually entering RTF markup into that control then this code from post #3:
vb.net Code:
ChatWindow.SelectedRtf = ChatEdit.Rtf
should be this:
vb.net Code:
ChatWindow.SelectedRtf = ChatEdit.Text
-
Nov 30th, 2020, 06:51 PM
#13
Thread Starter
Hyperactive Member
Re: Interpret Raw RTF Markup Text To RichTextBox?
no ChatEdit is the bottom left, ChatWindow top left.. the other plain textbox on the top right is only to see the RTF markup that is being edited in the ChatEdit (this is only for my testing and will be in a separate option/editor for users later.
I am using this in the main command button, Thanks jmcilhinney, ok but I need it to be able to post both.
So now the question is how can I change this code to be able to post both edited in the chatedit and also pasted raw RTF markup using the same chatedit richtextbox?
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.
'RichTextBox2.SelectedRtf = RichTextBox1.Rtf
ChatWindow.SelectedRtf = ChatEdit.Rtf
'Append a line break.
ChatWindow.AppendText(ControlChars.Lf)
ChatWindow.ScrollToCaret()
if that works for the edited chatedit that was edited in the richtextbox and this code below works for the raw RTF, how can I change this to do both things?
Code:
ChatWindow.SelectedRtf = "Raw RTF Data Here"
Last edited by DreamWarrior77; Nov 30th, 2020 at 07:08 PM.
-
Nov 30th, 2020, 09:21 PM
#14
Re: Interpret Raw RTF Markup Text To RichTextBox?
Originally Posted by DreamWarrior77
I need it to be able to post both.
You know how to do both, so there's no problem. If you're using one Button, you just need to use an If statement based on the appropriate condition to decide which to do. If you're using two Buttons then you just put different code in each Click event handler.
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
|