Paste before and after highlighted text

bbarclay

Member
Joined
Sep 15, 2006
Messages
23
Programming Experience
Beginner
Within my application i have a text editor which is kind of like a WYSIWIG editor. Does anyone know how to make it so you can highlight text and have button that will place text around it.

For instance. I click the bold button with the words "hello world" highlighted

After clicking the button it then says "<b>Hello world</b>" The text placed before it will be different than the text after.


This will function like a wysiwig but within visual studio 2005.


Thanks


Brandon
 
Here is some code where 'rtb' is a (Rich)TextBox control:
VB.NET:
[SIZE=2]
rtb.SelectedText = [/SIZE][SIZE=2][COLOR=#800000]"<b>"[/COLOR][/SIZE][SIZE=2] & rtb.SelectedText & [/SIZE][SIZE=2][COLOR=#800000]"</b>"
[/COLOR][/SIZE]
 
My button looked like this.

This worked perfect. Thank you for your quick response. This forum rocks.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] BoldBtn_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] BoldBtn.Click[/SIZE]
 
[SIZE=2]C.SelectedText = [/SIZE][SIZE=2][COLOR=#800000]"<b>[B]"[/B][/COLOR][/SIZE][B][SIZE=2] & C.SelectedText & [/SIZE][SIZE=2][COLOR=#800000]"</b>[/COLOR][/SIZE][/B][SIZE=2][COLOR=#800000]"[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

C was the name of the text box that I had.
 
Back
Top