ColorDialog, How to get color?

Getox

Centurion
Joined
Jul 8, 2004
Messages
122
Any way to get the hex code of the color from the ColorDialog?

My code:
codebox.SelectedText = "<font color='" + ColorDialog.Color + "'>" + codebox.SelectedText + "</font>"
 
Try:

codebox.SelectedText = "<font color='" + ColorDialog.Color.ToKnownColor.ToString + "'>" + codebox.SelectedText + "</font>"

The only problem is if the user selects a funky color, you'll get a "0". There's probably a solution for that though. :)
 
PlausiblyDamp said:
Scrappy as hell ;) put seemed to work
C#:
Color.Red.ToArgb().ToString("X").Substring(2);

I really, really hope there is a better and cleaner way than that though ;)
Do i have to do that for every color?

Here is my new code:

Visual Basic:
Dim text As String
        FontDialog.ShowColor = True
        If FontDialog.ShowDialog() = DialogResult.OK Then
            text = "<font style='font-size:" + FontDialog.Font.Size.ToString + "px;' face='" + FontDialog.Font.FontFamily.Name + "' color='" + FontDialog.Color.ToKnownColor.ToString + "'>" + codebox.SelectedText + "</font>"
            If FontDialog.Font.Underline = True Then
                text = "<u>" + text + "</u>"
            End If
            If FontDialog.Font.Italic = True Then
                text = "<i>" + text + "</i>"
            End If
            If FontDialog.Font.Bold = True Then
                text = "<strong>" + text + "</strong>"
            End If
            If FontDialog.Font.Strikeout = True Then
                text = "<s>" + text + "</s>"
            End If
            codebox.SelectedText = text
        End If
 
Back
Top