Change color of buttons inside another control in Visual Basic .NET

José Carlos 886 Reputation points
2023-07-05T15:07:42.9833333+00:00

Hi friends,

I have a VB routine to change the color of some buttons inside the flowLayoutPanel1 control.

It is giving error, stating that "Expression of type Control can never be of type VisualStyleElement.Button in line If TypeOf op1 Is Button Then.

I can't figure out the error.

Code:

		For Each op1 As Control In flowLayoutPanel1.Controls
			If TypeOf op1 Is Button Then
				Dim butt As Button = DirectCast(op1, Button)
				butt.BackColor = Color.PeachPuff ' Substitua pela cor desejada
			End If
		Next

Thank ou

Developer technologies | VB
Developer technologies | Visual Studio | Other
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2023-07-05T16:01:31.95+00:00

    Try specifying the full name: System.Windows.Forms.Button instead of Buttons. Or adjust the Imports directives.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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