Можно ли присвоить переменную различным динамическим меткам?
Is there a way I can assign a generic variable to a Dim label so that I can just loop 3 times. As shown there are a lot of repetitive statements and would love to shorten the code.
Что я уже пробовал:
<pre> Public Sub Draw_Player_Information() ScreenLocation_X = 10 : ScreenLocation_Y = 2 For counter = 0 To (Form1.DataGridView1.Rows.Count - 1) Dim PlayerNumberLabel As New Label Dim PlayerNameLabel As New Label Dim PlayerScoreLabel As New Label PlayerNumberLabel.Size = New Point(120, 70) PlayerNameLabel.AutoSize = True PlayerScoreLabel.AutoSize = True PlayerNumberLabel.FlatStyle = FlatStyle.Flat PlayerNameLabel.FlatStyle = FlatStyle.Flat PlayerScoreLabel.FlatStyle = FlatStyle.Flat PlayerNumberLabel.ForeColor = Form1.PlayerNumberButton.ForeColor PlayerNameLabel.ForeColor = Form1.PlayerNameButton.ForeColor PlayerScoreLabel.ForeColor = Form1.PlayerScoreButton.ForeColor PlayerNumberLabel.BackColor = Color.Transparent PlayerNameLabel.BackColor = Color.Transparent PlayerScoreLabel.BackColor = Color.Transparent PlayerNumberLabel.Text = Str(counter + 1) + "." PlayerNameLabel.Text = Form1.DataGridView1.Rows(counter).Cells("Column1").Value.ToString PlayerScoreLabel.Text = Form1.DataGridView1.Rows(counter).Cells("Column2").Value.ToString PlayerNumberLabel.TextAlign = ContentAlignment.TopRight PlayerNameLabel.TextAlign = ContentAlignment.MiddleLeft PlayerScoreLabel.TextAlign = ContentAlignment.TopRight PlayerNumberLabel.Font = New Font("Helvetica", 35, FontStyle.Bold) PlayerNameLabel.Font = New Font("Helvetica", 35, FontStyle.Bold) PlayerScoreLabel.Font = New Font("Helvetica", 35, FontStyle.Bold) PlayerNumberLabel.Location = New Point(ScreenLocation_X, ScreenLocation_Y) PlayerNameLabel.Location = New Point(ScreenLocation_X + 120, ScreenLocation_Y - 3) PlayerScoreLabel.Location = New Point(ScreenLocation_X + 350, ScreenLocation_Y) Form1.Panel4.Controls.Add(PlayerNumberLabel) Form1.Panel4.Controls.Add(PlayerNameButton) Form1.Panel4.Controls.Add(PlayerScoreLabel) ScreenLocation_Y += 65 : If ScreenLocation_Y > 950 Then ScreenLocation_X += 500 : ScreenLocation_Y = 0 Next End Sub