ProgrammingRookie
ProgrammingRookie

Reputation: 53

Changing TextBox ForeColor while it's disabled in Visual Basic .NET

I have been working on a Sudoku assignment and have come across a little problem.

I made buttons with the numbers that can be filled in. Now when I press any of these buttons, my method should run through all 81 textboxes on the form, and check it's '.Text' if this equals the button Tag, then I want the textbox' forecolor to be changed to green, whether it's disabled or not.

CODE:

Public Sub udsGetal(ByVal strSenderTag As String)
    For intBoxY As Integer = 0 To 2
        For intCellY As Integer = 0 To 2
            For intBoxX As Integer = 0 To 2
                For intCellX As Integer = 0 To 2
                    If getBox(intBoxX, intBoxY).getcell(intCellX, intCellY).text.Equals(strSenderTag) And getBox(intBoxX, intBoxY).getcell(intCellX, intCellY).enabled = True Then
                        getBox(intBoxX, intBoxY).getcell(intCellX, intCellY).forecolor = Color.Green
                    ElseIf getBox(intBoxX, intBoxY).getcell(intCellX, intCellY).text.Equals(strSenderTag) And getBox(intBoxX, intBoxY).getcell(intCellX, intCellY).enabled = False Then
                        getBox(intBoxX, intBoxY).getcell(intCellX, intCellY).enabled = True
                        getBox(intBoxX, intBoxY).getcell(intCellX, intCellY).forecolor()
                        getBox(intBoxX, intBoxY).getcell(intCellX, intCellY).enabled = False
                    End If
                Next
            Next
        Next
    Next
End Sub

Sadly, this did not work, I expect this to be because a disabled textbox, can't have it's color changed.

So my question is: Is there a work around for this problem?

Upvotes: 1

Views: 3299

Answers (1)

user8722218
user8722218

Reputation: 31

If you want to make your textbox "unchangeable" or "uneditable" and want to modify or change its forecolor and backcolor, never use the "enabled = false" property, instead, use "readonly = true." In that case, you may change textbox's forecolor and backcolor.

Upvotes: 3

Related Questions