Hello, I'm very new to VB, I have a small problem.

I'm simply trying to allow the user to change the ForeColor of some calculated totals that appear in Read-only text boxes using the Color Dialog box. I'm not sure what I'm doing wrong, any help would be appreciated.

Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
        'Allow user to select new color for summary totals.
        With Me.ColorDialog1
            .Color = Me.subTotalTextBox.ForeColor
            .ShowDialog()
            Me.subTotalTextBox.ForeColor = .Color
            Me.taxTextBox.ForeColor = .Color
            Me.totalTextBox.ForeColor = .Color
        End With

When I select a color the fore color remains the same. If I replace ForeColor with BackColor it works though..this seems so very simple but I just can't seem to get it to work.

Edited 6 Years Ago by ercdill: n/a

Hello, I'm very new to VB, I have a small problem.

I'm simply trying to allow the user to change the ForeColor of some calculated totals that appear in Read-only text boxes using the Color Dialog box. I'm not sure what I'm doing wrong, any help would be appreciated.

Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
        'Allow user to select new color for summary totals.
        With Me.ColorDialog1
            .Color = Me.subTotalTextBox.ForeColor
            .ShowDialog()
            Me.subTotalTextBox.ForeColor = .Color
            Me.taxTextBox.ForeColor = .Color
            Me.totalTextBox.ForeColor = .Color
        End With

When I select a color the fore color remains the same. If I replace ForeColor with BackColor it works though..this seems so very simple but I just can't seem to get it to work.

I got it working but I'd still appreciate if someone can chime in. After putting Google to use I've found that the Fore Color of Read Only text boxes are ignored unless the Back Color is also set. So I changed my code to:

Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal(e As System.EventArgs) Handles ColorToolStripMenuItem.Click
        'Allow user to select new color for summary totals.
        With Me.ColorDialog1
            .Color = Me.subTotalTextBox.ForeColor
            .ShowDialog()
            Me.subTotalTextBox.BackColor = Me.subTotalTextBox.BackColor
            Me.taxTextBox.BackColor = Me.taxTextBox.BackColor
            Me.totalTextBox.BackColor = Me.totalTextBox.BackColor
            Me.subTotalTextBox.ForeColor = .Color
            Me.taxTextBox.ForeColor = .Color
            Me.totalTextBox.ForeColor = .Color
        End With
    End Sub

and now I'm getting the results I expected.

Is this the only work around for this? It is working now but if I'm taking extra steps to accomplish something that can be done easier, I'd like to know. Thanks. :)

Edited 6 Years Ago by ercdill: n/a

' Working with and around the bug
' Remove some code redundancy with a function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cd As New ColorDialog
        If cd.ShowDialog = Windows.Forms.DialogResult.OK Then
            ChangeTextboxForeColor(txt1, cd.Color)
            ChangeTextboxForeColor(txt2, cd.Color)
            ChangeTextboxForeColor(txt3, cd.Color)
        End If
    End Sub
    Private Sub ChangeTextboxForeColor(ByVal txtName As TextBox, ByVal SelectedColor As System.Drawing.Color)
        With txtName
            .BackColor = .BackColor
            .ForeColor = SelectedColor
        End With
    End Sub
This article has been dead for over six months. Start a new discussion instead.