I am trying to remove a drawing from my winform. What is wrong with my code?
private void removeDrawing()
{
foreach (var ctrl in this.Controls)
{
if (ctrl.GetType().ToString() == "Microsoft.VisualBasic.PowerPacks.ShapeContainer")
{
this.Controls.Remove(ctrl); // argument type 'object' is not assignable to parameter type 'System.Windows.Forms.Control
}
}
}
[Update] Thanks for the answer. I implemented it as
while (this.Controls.OfType<ShapeContainer>().Any())
{
var ctrl = this.Controls.OfType<ShapeContainer>().First();
this.Controls.Remove(ctrl);
}