Hilight text in webbrowser that meets a criteria...
This may or maynot be possible, but thought I would ask the question anyway.
I have a webbrowser control on a form that I am using to allow my users to create custom email templates within my application. I then have a number of button on the form that enters predefined tags within the webbrowser that then I replace with valid data before sending the email. I will give you an example which will probably clarify it better, I have a button that inserts the users name into the webbrowser e.g. it add text [USER_FIRST_NAME] this then allows me to replace [USER_FIRST_NAME] with the actual users first name who sends the email. Therefore making this email templates.
The problem that the user when designing the email templates could click on the [USER_FIRST_NAME] tag text and edit each character. What I would like is when the user clicks in the webbrowser it somehow checks to see if the cursor is within a tag e.g. within the [ and ] and then hilights the whole tag. This would therefore not allow then to edit the content of the tag text.
I hope that makes sense? There are no spaces in my tags, all spaces have _ (underbars)
Thanks in advance
Simon
Re: Hilight text in webbrowser that meets a criteria...
If you are using web elements or whatever to do this, you can use the replace code:
RichTextBox1.Text = RichTextBox1.Text.Replace("[USER_FIRST_NAME]", "DesignLife")
Re: Hilight text in webbrowser that meets a criteria...
Just format it in a rich text box then use GetElementByID to locate the body for the email, then put the text from the RTB into it. You can play with the code to alter it and make it use names and such from a list box.
Re: Hilight text in webbrowser that meets a criteria...
DesignLife,
It was not the replacing the text that I was having an issue with, but hilighting the entire tag in the webbrowser control (same functionality if you double click a word in the webbrowser control is hilights the whole word) e.g. [USER_FIRST_NAME] if the user clicks anywhere inside the square brackets it hilights the whole tag from [ to ]. This will then stop them from editing the tag content to something that is not valid.
Re: Hilight text in webbrowser that meets a criteria...
Quote:
This will then stop them from editing the tag content to something that is not valid.
Er ... how? Highlighting doesn't stop anybody doing anything. Meanwhile it's far from clear exactly what you are wanting here. Are you using the webbrowser as an editor directly (an arcane process filled with delightful traps)? If the functionality is the same as the double click why don't you just turn a click into a double click?