(Danach möchte ich mir noch C++ aneignen, aber daran denke ich im Moment nicht.)
Jetzt die Frage: Ich habe folgendes geschrieben:
Code:
public partial class Form1 : Form
{
Label firstclicked = null;
Label secondclicked = null;
}
Kompletter Code zur Übersicht:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Random random = new Random();
List<string> icons = new List<string>()
{
"!", "!", "a", "a", "q", "q", "?", "?",
"x", "x", "b", "b"
};
private void AssignIconsToSquares()
{
foreach (Control control in tableLayoutPanel1.Controls)
{
Label iconlabel = control as Label;
if (iconlabel != null)
{
int randomNumber = random.Next(icons.Count);
iconlabel.Text = icons[randomNumber];
iconlabel.ForeColor = iconlabel.BackColor;
icons.RemoveAt(randomNumber);
}
}
}
public Form1()
{
InitializeComponent();
AssignIconsToSquares();
}
private void label_Click(object sender, EventArgs e)
{
Label clickedlabel = sender as Label;
if (clickedlabel != null)
{
if (clickedlabel.ForeColor == Color.Black)
return;
if (clickedlabel == null)
{
if (clickedlabel.ForeColor == Color.Black)
return;
if (firstclicked == null)
{
firstclicked = clickedlabel;
firstclicked.ForeColor = Color.Black;
return;
}
}
}
}
public partial class Form1 : Form
{
Label firstclicked = null;
Label secondclicked = null;
}
private void timer1_tick( object sender, EventArgs e)
{
timer1.Stop();
firstclicked.ForeColor = firstclicked.BackColor;
secondclicked.ForColor = secondclicked.BackColor;
firstclicked = null;
secondclicked = null;
}
private void label_Click(object sender, EventArgs e)
{
if (timer1.Enabled == true)
return;
Label clickedLabel = sender as Label;
if (clickedLabel != null)
{
if (clickedLabel.ForeColor == Color.Black)
return;
if (firstClicked == null)
{
firstClicked = clickedLabel;
firstClicked.ForeColor = Color.Black;
return;
}
secondClicked = clickedLabel;
secondClicked.ForeColor = Color.Black;
timer1.Start();
}
}
}
}
Kann mir eventuell jemand helfen?






