简体   繁体   中英

Hide textbox when a certain radiobutton is checked c#

I'm making a project where I want to hide more textboxes when a certain radiobutton if checked.

I have searched but I could not find a solution I could understand.

I have created a code under the radiobutton where a certain textbox should hide, but it does not work.

        private void buttonBeregn_Click(object sender, EventArgs e)
    {

        // oprettelse af nye objekter, som stammer fra superklassen objektet geometri
        // hver klasse får oprettet sit eget objekt nedarvet fra superklasse objektet geometri

        // Kassen
        if (radioButtonKasse.Checked)
        {

            textBoxRadius.Visible = false;

            try
            {
                radius = 0;
                længde = Convert.ToDouble(textBoxLængde.Text);
                bredde = Convert.ToDouble(textBoxBredde.Text);
                højde = Convert.ToDouble(textBoxHøjde.Text);

                geometri = new Kasse(længde, bredde, højde, radius);
            }

            catch
            {
                labelFejl.Text = "Du skal udfylde længde, bredde og højde";
            }
        }

Can someone tell me what I'm doing wrong? I guess that it is not the right place I put the code. Should I put the code in the designer instead?

Assuming you are using Windows Forms, you have to make sure your radio button's CheckedChanged event is properly attached to your event handler, buttonBeregn_Click .

To add this event handler, go to the properties for your radio button, open the Events window, and click the drop down for CheckedChanged . You should see your event handler listed. Select it and now your event handler should fire when the radio button is checked.

To prevent this issue in the future, let Visual Studio create the event handler for you by adding the event handler via the radio button properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM