Jump to content

Botão excluir textbox criada


Guilherme1974

Recommended Posts

Então, criei um panel com scroll e ao apertar o botão nele são criadas 1 textbox e 1 botão, segue o código:

private const int TextBoxX = 5;                
        private const int TextBoxWidth = 300;          
        private const int TextBoxY = TextBoxWidth + 10;
        public const int ButtonX = TextBoxY + 80; 

        private int _controlY = 5;                        
        
        public formCardapio()
        {
            InitializeComponent();
        }

       

        private void btn_adicionar_Click(object sender, EventArgs e)
        {


            panel1.Controls.AddRange(new Control[]

    {
        new TextBox
        {
            Text = txt_cardapio.Text,
            Location = new Point(TextBoxX, _controlY),
            Size = new Size(300, 20)

        },

        new TextBox
        {
            Text = Convert.ToString(txtpreço.Text),
            Enabled = true,
            Location = new Point(TextBoxY, _controlY),
            Size = new Size(80, 20)
        },

        new Button
        {
            Text = "Remover",
            Location = new Point(ButtonX, _controlY),
            Size = new Size(100, 20)
        }


    });

            _controlY += 25;
            
            
        }

Agora minha duvida é, como eu adiciono um comando ao clicar nesse botão criado, quero que ao clicar nele o textbox criado seja excluido, alguem pode me ajudar

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.