0

Who can help me with the following

For Each Con As Control In GroupBox1.Controls
            If Con.GetType Is GetType(Button) Then
                Con.BackColor = SystemColors.Control
                Con.UseVisualStyleBackColor = True
            End If
        Next

Can someone help me to fix it with
Con.UseVisualStyleBackColor = True

or do i have to do the for all buttons separate
like Me.Button1.UseVisualStyleBackColor = True
Me.Button2.UseVisualStyleBackColor = True

i have 32 buttons in groupbox

thanks in advice John

Edited by johnnyd1963

2
Contributors
3
Replies
15
Views
2 Months
Discussion Span
Last Post by Reverend Jim
1

UseVisualStyleBackColor is True by default. To set other properties for all buttons you could do, as an example

For Each btn As Button In GroupBox1.Controls.OfType(Of Button)()
    btn.BackColor = Color.Cyan
Next

You can't change the defaults like

Button.DefaultBackColor = Color.Cyan

because default properties are read-only.

Edited by Reverend Jim

0

Oke. Than i have to do for each button separate like

Me.Button1.UseVisualStyleBackColor = True

and that work it's only a lot typing.
thanks

0

You didn't read my answer. UseVisualStyleBackColor = True is the default. In any case, if you want to set the same base settings for a bunch of controls at design time, just select them all then set the properties. Or you can create one button with the properties you want, then copy/paste to get the rest.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.