How to choose font color to be displayed in my windows dialog box (windows form) after running the program

sead saric 0 Reputation points
2026-11-29T19:49:49.8566667+00:00

How to choose font color to be displayed in my windows dialog box (windows form) after running the program

Developer technologies | VB
0 comments No comments

2 answers

Sort by: Oldest
  1. AI answer

    2026-11-29T19:50:27.3866667+00:00

    Use a Windows Forms ColorDialog, then assign its selected Color to the control’s ForeColor property when the user clicks OK.^1^

    Let the user choose the font color at runtime

    1. Open the form in the Visual Studio Designer.
    2. From Toolbox → Dialogs, drag a ColorDialog onto the form. It appears in the component tray as ColorDialog1.
    3. Add a button named ButtonChooseColor.
    4. Double-click the button and add:
    Private Sub ButtonChooseColor_Click(
        sender As Object,
        e As EventArgs
    ) Handles ButtonChooseColor.Click
    
        ColorDialog1.Color = Label1.ForeColor
    
        If ColorDialog1.ShowDialog() = DialogResult.OK Then
            Label1.ForeColor = ColorDialog1.Color
        End If
    End Sub
    

    Replace Label1 with the control whose text should change, such as:

    TextBox1.ForeColor = ColorDialog1.Color
    Button1.ForeColor = ColorDialog1.Color
    RichTextBox1.ForeColor = ColorDialog1.Color
    

    Setting ColorDialog1.Color before showing the dialog makes the control’s current text color the initially selected color. If no color has been selected, the dialog’s default Color value is black.^2^

    To apply the selected font color to the form itself and controls that inherit its foreground color, use:

    If ColorDialog1.ShowDialog() = DialogResult.OK Then
        Me.ForeColor = ColorDialog1.Color
    End If
    

    Set a fixed color instead

    If the color does not need to be selected at runtime, set it in either of these ways:

    • Designer: Select the control → Properties → ForeColor → choose a color.
    • Code:
    Private Sub Form1_Load(
        sender As Object,
        e As EventArgs
    ) Handles MyBase.Load
    
        Label1.ForeColor = Color.Crimson
    End Sub
    

    ForeColor changes the text color; BackColor changes the background color.

    Keep the choice after restarting the application

    If the selected color must remain after the application closes, store it in a user-scoped application setting. Only user-scoped settings can be changed and persisted at runtime; application-scoped settings are read-only.^3^

    Create a setting such as FontColor with:

    • Type: System.Drawing.Color
    • Scope: User
    • Default value: Black

    Then save and restore it:

    ' After the user selects a color:
    Label1.ForeColor = ColorDialog1.Color
    My.Settings.FontColor = ColorDialog1.Color
    My.Settings.Save()
    
    ' In the form's Load event:
    Label1.ForeColor = My.Settings.FontColor
    

    References

    1. How to: Show a Color Palette with the ColorDialog Component
    2. ColorDialog.Color Property-Definition
    3. How to properly set a settings.settings file properties for a windows setup project in visual studio - Microsoft Q&A
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

  2. Nguyen Dam (WICLOUD CORPORATION) 1,910 Reputation points Microsoft External Staff Moderator
    2026-11-30T02:40:20.8833333+00:00

    Hello @sead saric and thank you for your question. 

    To do this, you essentially only need to create an input that can change the color value (ForeColor) of the text (Label). 

    One of the simplest ways would be to use a ComboBox. Here's a VB.NET example: 

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load      
    	ComboBox1.Items.AddRange({"Red", "Green", "Blue", "Black"})  
    End Sub    
    
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged     
    	Label1.ForeColor = Color.FromName(ComboBox1.SelectedItem.ToString())  
    End Sub
    

    Other than that, you can also change the font color using a TextBox, TrackBar, ColorDialog, Button, or CheckBox. 

    If you'd like to explore these alternatives, you can check out the Windows Forms controls documentation. While it isn't specific to VB.NET, the controls described there also apply to VB.NET Windows Forms applications. 

    If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation. Thank you.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.