1
我想從我的winform中移除一個圖形。 我的代碼有什麼問題?參數類型'對象'不能分配給參數類型'System.Windows.Forms.Control
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
}
}
}
[更新] 感謝您的回答。 我實現它作爲
while (this.Controls.OfType<ShapeContainer>().Any())
{
var ctrl = this.Controls.OfType<ShapeContainer>().First();
this.Controls.Remove(ctrl);
}