开发者

What parameter has controls.remove() method in winforms?

What parameter has controls.remove() method in开发者_C百科 winforms? I want to remove some element from a form. What should I pass into the remove method - its id or something else?


The controls property is a Control.ControlCollection. To remove a control from this collection, you need to pass in an instance of the control you want to remove.

The MSDN docs has an example:

private void removeButton_Click(object sender, System.EventArgs e)
{
   if (panel1.Controls.Contains(removeButton))
   {
      panel1.Controls.Remove(removeButton);
   }
}

To answer the question in your comment:

You cannot remove it by its id or name, but you can find the instance of your control by passing its name into the Find method on the Controls property. This returns as array of all controls that have the specified name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜