I have a problem with backcolor.

Poppa Mintin

Well-known member
Joined
Jan 4, 2018
Messages
45
Programming Experience
10+
Hi,

Here is code for generating a number of buttons on myForm1.

VB.NET:
    Private Sub Buts()
        Dim num As Int32 = 0
        Dim fnt As New System.Drawing.Font("Comic Sans MS", CInt(gap * 0.38))

        For i = 1 To col
            For j = 1 To row
                num += 1
                Dim butn As New Button
                With butn
                    .BackgroundImageLayout = ImageLayout.None
                    .FlatStyle = FlatStyle.Flat
                    .FlatAppearance.BorderSize = 0
                    .Enabled = False
                    .Name = "Button" & num.ToString
                    .Height = box + qrt
                    .Width = box + qrt
                    .Location = spot(num)
                    .BackColor = Me.BackColor
                    .ForeColor = Color.Red
                    .Font = fnt
                    .Text = initial
                End With
                Me.Controls.Add(butn)
            Next
        Next
    End Sub
For the purposes of this question suffice to say everything works just fine, I can generate anything from 25 to 150 buttons as selected by the user. So I have no need to explain all the variables, they're irrelevant.

Here's the problem:
VB.NET:
     .ForeColor = Color.Red
No matter what colour I select for the ForeColor of these buttons I always get a sort of dirty blue to dirty grey text.
Changing the form's BackColor has no effect from Color.White or (say) Color.Yellow, makes no difference.
Even a Color.White ForeColor on a Color.White BackColor the text is grey.

What's going on ?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,345
Location
Sydney, Australia
Programming Experience
10+
It's because the Button is disabled. A disabled Button is greyed out. Don't set Enabled to False and you'll see the ForeColor you set. If this relates to your other question then it seems that you should be using Labels instead of Buttons and then there's no need to disable anything because a Label isn't inherently clickable like a Button is.
 

Poppa Mintin

Well-known member
Joined
Jan 4, 2018
Messages
45
Programming Experience
10+
Ah !

OK... Thanks John.

I disabled it because I didn't want it to be clicked, but... Thinking about that, if there's no click subroutine it won't matter if it's clicked or not.


Poppa.
 
Top Bottom