Hi.
I'm working on a program where a number of buttons is being created based on information in a database. Later in my code I will like to change background color on some of the buttons to show their status. I would normally use Button1.BackColor = Color.Red, but I don't know how to call the buttons when they are created during run time. Like you can see in below code, the first button will get the name "Knap1". How do I change this buttons color to red?
I hope somebody know how.
Thank you in advance.
/ Ole
I'm working on a program where a number of buttons is being created based on information in a database. Later in my code I will like to change background color on some of the buttons to show their status. I would normally use Button1.BackColor = Color.Red, but I don't know how to call the buttons when they are created during run time. Like you can see in below code, the first button will get the name "Knap1". How do I change this buttons color to red?
Try con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Ole\Documents\Visual Studio 2012\Projects\TMS\TMS-database.accdb") con.Open() Catch ex As Exception MsgBox("Database ikke fundet. Fejl 1") End Try sqlStr = "Select * from Medarbejdere" cmd = New OleDb.OleDbCommand(sqlStr, con) dr = cmd.ExecuteReader() Dim Y As Integer = 1 Do While dr.Read() Dim btn = New Button() btn.Name = "Knap" & Y btn.Text = dr(3) btn.Location = New Point(10, Y * 30) Panel1.Controls.Add(btn) AddHandler btn.Click, AddressOf Me.ButtonClicked Y = Y + 1 Loop con.Close()
I hope somebody know how.
Thank you in advance.
/ Ole
Last edited by a moderator: