Monday, March 13, 2006 11:36 AM
Every now and then I need to create a color object in my code, but don’t know exactly what color I want. So I created this little macro to popup the ColorDialog, then insert a little line of code for the color you picked.
Nothing magic or special here, just another useful macro. The only problem with it is the color dialog comes up behind Visual Studio so you have to Alt-Tab to see it. A bit annoying, I know. If anyone figures that one out I'll post the fix.
Public Sub ColorPicker()
Dim colorDlg As New ColorDialog
colorDlg.AllowFullOpen = True
colorDlg.AnyColor = True
colorDlg.FullOpen = True
colorDlg.SolidColorOnly = False
Dim ret As DialogResult = colorDlg.ShowDialog()
If ret = DialogResult. Cancel Then
Return
End If
Dim color As System.Drawing.Color = colorDlg.Color
Dim code As String
If color.IsNamedColor Then
code = "Color color = Color." + color.Name + ";"
Else
code = "Color color = Color.FromArgb(" + color.ToArgb().ToString() + ");"
End If
Dim textSelection As TextSelection = DTE.ActiveDocument.Selection()
Dim edit As EditPoint = textSelection.TopPoint.CreateEditPoint()
edit.Insert(code)
End Sub