9 Replies - 2276 Views - Last Post: 22 January 2012 - 07:41 PM Rate Topic: -----

#1 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

help with inserting text into a rich textbox based on selected text ..

Posted 08 January 2012 - 08:39 PM

Hello all, i'm back to the use of RTB and again have a question, and couldn't find the help at least relevant help for this issue...

What I am trying to do:

I need to insert formatting HTML tags in the rtb before and after the word(s) selected. so that when you select a word: "this" in the middle of a sentence, and press the "Bold" button (formatted text must be in HTML as it is a email... and RTB formatting doesnt work...) it will insert "<strong>this</strong>" in the place of the word "this"...

What I have tried:
I attempted to use the native Rich text formatting that works great for documents, but dosent work with out html code tags when its sent over email. It is necessary for the formatting to be there... It works if i push the formatting tags to the end of the text box, but it still means cut and paste, which is a step i wish to avoid.

I attempted to find where the selected text started, and the text selected length But this failed , and would either through an RTE 5, or do nothing. This is frustrating, I know there is a way to do it... i just cant find it... GRRRRR!!!

Google searches show plenty of help with it in .Net, which for this application i need to create both a .net GUI and a com GUI. its irritating, but its what has to happen, Any advice???

Thanks

Jesse Fender

Is This A Good Question/Topic? 0
  • +

Replies To: help with inserting text into a rich textbox based on selected text ..

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: help with inserting text into a rich textbox based on selected text ..

Posted 08 January 2012 - 09:38 PM

Can't you declare a string and put the text in it?
Dim strong As String
strong = "<strong>" & RTB.SelText & "</strong>"
Replace(RTB.SelText, strong)


I'm not too sure about the replacing bit - I'm better with VB.Net. But you get the idea right?
Cheers :)!
Was This Post Helpful? 0
  • +
  • -

#3 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,770
  • Joined: 26-March 09

Re: help with inserting text into a rich textbox based on selected text ..

Posted 09 January 2012 - 01:33 AM

Can you not just use something like:

rtbText.SelText = "My new text string"

Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: help with inserting text into a rich textbox based on selected text ..

Posted 15 January 2012 - 01:51 PM

VB6 uses RTF 1.0 in the control, so as to not lose backward compatibility with older versions. If you want to use features in later versions (direct access to the RTF formatting, for example), you have to trick VB6 and get at TOM directly.

The basic technique takes advantage of the fact that the RTF control is a COM object. As such, it is required to expose an iUnknown interface, which contains a QueryInterface method which returns the supported interfaces of the object. One of these is an implementation of the Text Object Model, or TOM.

Here's a thread where I went into an explanation of how to do this.

Also, here is a microsoft explanation of the different features of the different rich text versions supported by various rich edit controls. Version 4.1 is the latest supported version; all later versions are exclusively supported in various versions of Microsoft Office. As such, you will want to trick the RichText control into supporting RTF 4.1, contained in Msftedit.dll.

This post has been edited by BobRodes: 15 January 2012 - 02:16 PM

Was This Post Helpful? 0
  • +
  • -

#5 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: help with inserting text into a rich textbox based on selected text ..

Posted 18 January 2012 - 04:15 PM

Bob??? Where is your explanation???
Was This Post Helpful? 0
  • +
  • -

#6 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: help with inserting text into a rich textbox based on selected text ..

Posted 18 January 2012 - 07:13 PM

Sorry dude, I was at work and had trouble accessing it and forgot about you. Here you go. Interesting stuff! :)
Was This Post Helpful? 0
  • +
  • -

#7 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: help with inserting text into a rich textbox based on selected text ..

Posted 19 January 2012 - 07:52 PM

View PostBobRodes, on 18 January 2012 - 06:13 PM, said:

Sorry dude, I was at work and had trouble accessing it and forgot about you. Here you go. Interesting stuff! :)


Well it is deffinatly something interesting... I tried to figure it out reading all of the posts and I am still quite lost. I can get it to print random chunks of text ( and I am sure that given a bit more time to get it worked out I might be able to get control over the blasted thing.) but I cant seem to get it to only grab the selected text, once I get that I'm pretty sure that I can get it to delete the selected text and insert the wrapped text. which would do what I want it to do. it really should not be this difficult -

take a string find the text, save teh selected text to a string, warp it with the given tags, clear the selected text, insert the wrapped text sring back in the txt area, using selstart and seltext... and then move on...

That is really all I am trying to do.

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: help with inserting text into a rich textbox based on selected text ..

Posted 19 January 2012 - 08:39 PM

Oh, thought you were trying to control the metadata. I tried this out, and it should get you started. Just put a rtbox (or regular textbox will do it too), and a command button. Enter some text, highlight some of it, and hit the button. I'll leave you to investigate why there's an extra character in the result, and whether it works ok if you highlight the first and/or last characters in the text.
Private Sub Command1_Click()
MsgBox Mid(rtb.Text, 1, rtb.SelStart) & "<mytag this=""whatever"" that=""whatever2"">" & rtb.SelText & "</mytag>" & Mid(rtb.Text, rtb.SelStart + rtb.SelLength, Len(rtb.Text))
End Sub

Was This Post Helpful? 1
  • +
  • -

#9 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: help with inserting text into a rich textbox based on selected text ..

Posted 21 January 2012 - 09:05 AM

View PostBobRodes, on 19 January 2012 - 07:39 PM, said:

Oh, thought you were trying to control the metadata. I tried this out, and it should get you started. Just put a rtbox (or regular textbox will do it too), and a command button. Enter some text, highlight some of it, and hit the button. I'll leave you to investigate why there's an extra character in the result, and whether it works ok if you highlight the first and/or last characters in the text.
Private Sub Command1_Click()
MsgBox Mid(rtb.Text, 1, rtb.SelStart) & "<mytag this=""whatever"" that=""whatever2"">" & rtb.SelText & "</mytag>" & Mid(rtb.Text, rtb.SelStart + rtb.SelLength, Len(rtb.Text))
End Sub


The corrected code( I figured it out with in minutes :D )
Mid(rtb.Text, rtb.SelStart + rtb.SelLength + 1, Len(rtb.Text))

The addition of the +1 moves forward one and removed the "extra" character...

This solved my issue, Thank you for the help guys,

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#10 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: help with inserting text into a rich textbox based on selected text ..

Posted 22 January 2012 - 07:41 PM

You're welcome.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1