Hi guys,
I have some problems regarding textbox and radiobutton. My GUI design is like this: I have a textbox, 3 radiobuttons and an enter button.
My first question: how can I make the enter button only visible if the textbox is filled and the radiobutton is clicked? If not it will be invisible.

Second question: How can I know which radiobutton was selected? Other than doing if else, is there any other smarter way to do it?

I hope you can help me with this. Thank you in advance:)

1st of all, if you use radionButton, there is always one selected (its not the same as checkBoxes, where you can deselect all). Ok, its possible to deselect all radionButtons in a group as well, but this is not the purpose then in using radionButtons.

About showing the button control, when there is some text inside a textBox, you can use a Length property to check how long is the actual text, and show/hide button based on that - inisde the TextChanged event (just subscribe to in, on double clicking on it in winform designer:

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if(textBox1.Text.Length == 0) //checking if there is any text inside textBox - if there is at least 1 character, buttoon will show up
    {
        button1.Visible = false;
    }
    else
    {
        button1.Visible = true;
    }
}

Try this :

        RadioButton r = null;//Selected RadioButton

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            r = (RadioButton)sender;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            r = (RadioButton)sender;
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            r = (RadioButton)sender;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (this.textBox1.TextLength > 0 && r != null)
            {
                button1.Visible = true;
            }
            else {
                button1.Visible = false;
            }
        }

Thank you guys. Both of your suggestions are great and very helpfull.

p/s: Mitja Bonca, I already set one of my RadioButton to checked as your advised:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.