Results 1 to 14 of 14

Thread: Interpret Raw RTF Markup Text To RichTextBox?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    279

    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.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    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?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    279

    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.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    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:
    1. ChatWindow.SelectionStart = ChatWindow.TextLength
    2. ChatEdit.SelectAll()
    3. ChatEdit.Copy()
    4. ChatWindow.Paste(DataFormats.GetFormat(DataFormats.Rtf))
    Specifying the format when pasting may not be required.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    279

    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.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: Interpret Raw RTF Markup Text To RichTextBox?

    I just tested this and it seemed to work for me:
    vb.net Code:
    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2.     RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Bold)
    3. End Sub
    4.  
    5. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    6.     RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Italic)
    7. End Sub
    8.  
    9. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    10.     RichTextBox1.SelectionColor = Color.Red
    11. End Sub
    12.  
    13. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    14.     RichTextBox1.SelectAll()
    15.     RichTextBox1.Cut()
    16.  
    17.     RichTextBox2.SelectionStart = RichTextBox2.TextLength
    18.     RichTextBox2.Paste()
    19.     RichTextBox2.AppendText(ControlChars.Lf)
    20. End Sub

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    279

    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..

    Name:  How To Send Raw RTF To ChatWindow.jpg
Views: 64
Size:  11.8 KB

    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.

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,491

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    279

    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..

  10. #10
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,657

    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.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    279

    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.

  12. #12
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    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:
    1. ChatWindow.SelectedRtf = ChatEdit.Rtf
    should be this:
    vb.net Code:
    1. ChatWindow.SelectedRtf = ChatEdit.Text

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    279

    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.

  14. #14
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: Interpret Raw RTF Markup Text To RichTextBox?

    Quote Originally Posted by DreamWarrior77 View Post
    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
  •  



Click Here to Expand Forum to Full Width