private void GenerateCards() { YourScore.Show(); YourScore.Text = "Your Score: 0"; OpponentsScore.Show(); OpponentsScore.Text = "Opponent's Score: 0"; _opponentPic = new PictureBox { Name = "Opponent's Card", Image = Resources.card_back_blue, Location = new Point(Width - 125, 10), Size = new Size(100, 114), SizeMode = PictureBoxSizeMode.StretchImage }; Controls.Add(_opponentPic); Point nextLocation = new Point(10, 134); for (int i = 0; i < 10; i++) { PictureBox currentPic = new PictureBox { Name = "picDynamic" + i, Image = Resources.card_back_red, Location = nextLocation, Size = new Size(100, 114), SizeMode = PictureBoxSizeMode.StretchImage }; currentPic.Click += (sender, e) => { if (!string.IsNullOrEmpty(_drawnCard)) { return; } // Generate a random card _drawnCard = RandomCard(); currentPic.Name = _drawnCard; currentPic.Image = (Image)Resources.ResourceManager.GetObject(FileNameByCard(currentPic.Name)); _amountOfOpenedCards++; // Send the Generated card BeginSend("1" + currentPic.Name); // Receive an answer BeginRead(); // Remove click event handler FieldInfo currentPicFieldInfo = typeof(Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic); object obj = currentPicFieldInfo?.GetValue(currentPic); PropertyInfo currentPicPropertyInfo = currentPic.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance); EventHandlerList list = (EventHandlerList)currentPicPropertyInfo?.GetValue(currentPic, null); list?.RemoveHandler(obj, list[obj]); }; Controls.Add(currentPic); nextLocation.X += currentPic.Size.Width + 10; MainButton.Text = "Forfiet"; } }