Poslao: 27 Nov 2016 16:00
|
offline
- Pridružio: 01 Nov 2015
- Poruke: 66
|
I am trying to make game that you have 12 random letters and with them you should make longest possible word that exist in ditionary.I want to loop through all labels and every time button is clicked each label separatly stops generating letters,when 12 label stops generating letters timer should stop.
Here is code in VB 6 that does this,in VB 6 all labels have name property lblSlovo
Private Sub lblStartStop_Click()
If Not lblStartStop.Enabled Then Exit Sub
If lblStartStop.Caption = "Start" Then
i = 0
Timor.Enabled = True
lblStartStop.Caption = "Stop"
lblStartStop.Enabled = True
Else
lblSlovo(i).Caption = slova(i)
i = i + 1
If i = 12 Then
txtInput.Enabled = True
lblStartStop.Enabled = False
lblStartStop.Caption = "Start"
Timor.Enabled = False
Vreme.Enabled = True
txtInput.SetFocus
End If
End If
End Sub
How to convert this code to C#.I cannot give same name property to all labels!!!
|
|
|
Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
|
|
Poslao: 27 Nov 2016 16:13
|
offline
- vasa.93
- Moderator foruma
- Pridružio: 17 Dec 2007
- Poruke: 14824
- Gde živiš: Niš
|
Možeš da napraviš polje ili listu labela, pa da im pristupaš preko indeksa kao u priloženom isečku koda.
|
|
|
|
Poslao: 27 Nov 2016 16:14
|
offline
- Pridružio: 01 Nov 2015
- Poruke: 66
|
Ovako?
slova[0] = Convert.ToString(label1);
slova[1] = Convert.ToString(label2);
slova[2] = Convert.ToString(label3);
slova[3] = Convert.ToString(label4);
slova[4] = Convert.ToString(label5);
slova[5] = Convert.ToString(label6);
slova[6] = Convert.ToString(label7);
slova[7] = Convert.ToString(label8);
slova[8] = Convert.ToString(label9);
slova[9] = Convert.ToString(label10);
slova[10] = Convert.ToString(label11);
slova[11] = Convert.ToString(label12);
|
|
|
|
Poslao: 27 Nov 2016 16:17
|
offline
- vasa.93
- Moderator foruma
- Pridružio: 17 Dec 2007
- Poruke: 14824
- Gde živiš: Niš
|
Ili još lakše ovako:
for(int i = 0; i < 12; i++)
slova[i] = labele[i];
|
|
|
|
Poslao: 27 Nov 2016 16:20
|
offline
- Pridružio: 01 Nov 2015
- Poruke: 66
|
Kada napisem for(int i = 0; i < 12; i++) slova[i] = label[i]; dobijem error the name label does not exist in current context!!!
|
|
|
|
Poslao: 27 Nov 2016 16:21
|
offline
- vasa.93
- Moderator foruma
- Pridružio: 17 Dec 2007
- Poruke: 14824
- Gde živiš: Niš
|
Upravo. Ako želiš da im pristupaš preko indeksa, moraš da uradiš najpre ovo:
vasa.93 ::Možeš da napraviš polje ili listu labela...
|
|
|
|
Poslao: 27 Nov 2016 16:26
|
offline
- Pridružio: 01 Nov 2015
- Poruke: 66
|
Mislis na ovo:
Label[] label = new Label[] {label1, label2, label3, label4, label5, label6, label7, label8, label9, label10, label1, label2};
|
|
|
|
|
Poslao: 27 Nov 2016 16:30
|
offline
- Pridružio: 01 Nov 2015
- Poruke: 66
|
Sad kad napisem for(int i = 0; i < 12; i++) slova[i] = label[i]; dobijem error cannot implicitly convert type System.Windows.Forms.Label to string
|
|
|
|
Poslao: 27 Nov 2016 16:37
|
offline
- vasa.93
- Moderator foruma
- Pridružio: 17 Dec 2007
- Poruke: 14824
- Gde živiš: Niš
|
A, jest, moja greška. Treba da pokupiš Caption (a možda je i Text, proveri) property iz labele.
Nego, pobogu, zar još uvek nisi shvatio osnovne principe programiranja?
|
|
|
|