Support Forums

Full Version: VB.NET Wrap Color BBCode Tags [Reply]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I didn't want to keep it up in PM's so i'm dragging this to the forum where it belongs:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ColDlg As New ColorDialog
    With ColDlg
        .FullOpen = True
        .ShowDialog()
    End With

    Dim HexColorVal As String = String.Format("{0:X2}{1:X2}{2:X2}", ColDlg.Color.R, ColDlg.Color.G, ColDlg.Color.B)
    TextBox1.SelectedText = AddBBCode(TextBox1.SelectedText, "[color=#" & HexColorVal & "]", "[/color]")
End Sub

Private Function AddBBCode(ByVal StartTag As String, ByVal EndTag As String) As String
    Dim L_ST As Integer = StartTag.Length
    Return TextBox1.SelectedText.Insert(0, StartTag).Insert(TextBox1.SelectedText.Length + L_ST, EndTag)
End Function

There, custom color dialog that wraps selected text in color bbcode tags.
Thanks man, really helped out. Your are the best! I am becoming 10x more active on SF.
I created a quick project out of the code I came up with as well just out of boredom. http://tech.reboot.pro/showthread.php?tid=2105

[Image: 6DZmH.png]
So you highlight some text, click the button, pick a colour, and it adds the BBCode around the selected text?
Pretty cool. I did something similar a few years back, only it was for a multi-colour text generator for forums and MSN, so the process was a bit different.
Yeah you have the idea of what it does Smile

If you don't input a value specified by some tags, or you don't have anything selected, it will put your ibeam between the tags so you can start typing right after you hit the button too.
Ace, you should add in a "preview" button mate, so the app holder can see what their post will be like.
That's an idea, and I was thinking about it too at the time I started this, but left it out after I started working on other things here.

I'll give the user the option to choose their own post template so that it works for other forums as well if I get around to upgrading this program.
Testing
[Image: q3fyv.png]
Looks good Hockey Smile Keep up the good work, I know I took off from the idea trying to help you, but I do know of someone that created something similar to this before me as well.

Can't wait to see the finished product when you're done Smile