且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

隐藏在c#.net中动态添加的按钮?

更新时间:2023-02-11 21:49:58

您需要获取要隐藏的控件的引用。在这种情况下,您很幸运地将其作为参数。

You need to get a reference to the control you want to hide. In this case you luckily get it as a parameter.
public void newPanelcategory_Click(object sender, EventArgs e)
{
    Button buttonToHide = sender as Button;
    if(buttonToHide == null)
    {
        // Method has been called by a control that is not a button.
        //   That is unexpected.
    }
    buttonToHide.Visible = false;

    // Remaining stuff
    // ...
}


newPanelcategory.Visible = false;