So thats my code, it works with a button but it doesnt work with my OvalShape. I need it for a Master Mind game in C#. The Oval shape should Change the Color after clicking on it. Its supposed to be able to Change into 6 Colors Red,Yellow,Blue,White,Green and Purple.
private void ovalShape1_4_Click(object sender, EventArgs e)
{
Control ctrl = ((Control)sender);
switch (ctrl.BackColor.Name)
{
case "Red":
ctrl.BackColor = Color.Yellow;
break;
case "Black":
ctrl.BackColor = Color.Green;
break;
case "White":
ctrl.BackColor = Color.Red;
break;
case "Yellow":
ctrl.BackColor = Color.Purple;
break;
default:
ctrl.BackColor = Color.Red;
break;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic.PowerPacks;
namespace Mastermind2
{
public static class ControlCollectionExtension
{
public static IList<OvalShape> ToList(this ShapeCollection aiShapeCollection)
{
IList<OvalShape> aoShapes = new List<OvalShape>();
foreach (OvalShape ctrl in aiShapeCollection)
aoShapes.Add(ctrl);
return aoShapes;
}
}
}
make public variable
after that make this logic, may this help you