private void btnAdd_Click(object sender, EventArgs e) { int indexLamp = lbLamps.SelectedIndex; int indexAction = lbActions.SelectedIndex; if (indexLamp > -1 && indexAction > -1) { Lamp l = (Lamp)lbLamps.Items[indexLamp]; Object o = lbActions.Items[indexAction]; if (o is Power) { PowerCommand pc = new PowerCommand(l, Convert.ToBoolean(o)); cal.AddAnimation(pc); } else if (o is Color) { AnimationCommand ac = new AnimationCommand(l, (Color)o); cal.AddAnimation(ac); } } }