using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); radioButton5.Text = "TEP Code RB5"; radioButton6.Text = "TEP Code RB6"; radioButton7.Text = "TEP Code RB7"; radioButton8.Text = "TEP Code RB8"; } } }It depends on your ease, you can use the both method to set the name of radio buttons. For your better understanding, we have attached the screenshot of output along with the code.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); radioButton1.Checked = true; } } }If you will add more radio buttons checked true then the only last radio button will be checked. Because you can only be checked one radio button at the same time. In the following image, you can preview that only radio button1 is checked.
using System; using System.Drawing; using System.Windows.Forms; namespace strnull { public partial class Form1 : Form { public Form1() { InitializeComponent(); radioButton1.BackColor = Color.AliceBlue; radioButton2.BackColor = Color.AntiqueWhite; radioButton3.BackColor = Color.Aqua; radioButton4.BackColor = Color.Aquamarine; radioButton5.BackColor = Color.Azure; radioButton6.BackColor = Color.Beige; radioButton7.BackColor = Color.Bisque; radioButton8.BackColor = Color.BlueViolet; } } }You must have to use the Color object to set any color. For the better understanding, we have taken the screenshot of output along with the code which is overriding the color properties.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); radioButton1.ForeColor = Color.YellowGreen; radioButton2.ForeColor = Color.Tomato; radioButton3.ForeColor = Color.Violet; radioButton4.ForeColor = Color.Turquoise; radioButton5.ForeColor = Color.SteelBlue; radioButton6.ForeColor = Color.Sienna; radioButton7.ForeColor = Color.SeaGreen; radioButton8.ForeColor = Color.BlueViolet; } } }We used the Color object to set the color. In the following image, you can observe that how the color changes the appearance and interface. By using the color schemes you can make eye attractive windows form and make easier for the user to identified usable features of your app.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); radioButton1.Font = new Font(Font.FontFamily,10); radioButton2.Font = new Font(Font.FontFamily, 11); radioButton3.Font = new Font(Font.FontFamily, 12); radioButton4.Font = new Font(Font.FontFamily, 13); radioButton5.Font = new Font(Font.FontFamily, 12); radioButton6.Font = new Font(Font.FontFamily, 11); radioButton7.Font = new Font(Font.FontFamily, 10); radioButton8.Font = new Font(Font.FontFamily, 9); } } }In the above code, we have used a different size for each RadioButton. The first four RadioButton size is increased and other four RadioButton size get a decrease. In the following image, you can observe the size of radio buttons.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); radioButton1.Font = new Font("Times New Roman", 11); radioButton2.Font = new Font("Century", 11); radioButton3.Font = new Font("Arial", 11); radioButton4.Font = new Font("Comic Sans MS", 11); radioButton5.Font = new Font("Copperplate Gothic Light", 11); radioButton6.Font = new Font("Georgia", 11); radioButton7.Font = new Font("Impact", 11); radioButton8.Font = new Font("Lucida Console", 11); } } }All the above-used fonts are the default font which is available in Windows. If you don't know which font you have to used then used Google Font. It will help you to select the best font for your desktop application. In the following image, you can observe how font changes the appearance of your desktop application.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked == true) { MessageBox.Show(radioButton1.Text); } else if (radioButton2.Checked == true) { MessageBox.Show(radioButton2.Text); } else if (radioButton3.Checked == true) { MessageBox.Show(radioButton3.Text); } else if (radioButton4.Checked == true) { MessageBox.Show(radioButton4.Text); } else if (radioButton5.Checked == true) { MessageBox.Show(radioButton5.Text); } else if (radioButton6.Checked == true) { MessageBox.Show(radioButton6.Text); } else if (radioButton7.Checked == true) { MessageBox.Show(radioButton7.Text); } else if (radioButton8.Checked == true) { MessageBox.Show(radioButton8.Text); } } } }If you want to try the above code in your own compiler, then you have to add button click event first then you can execute the above code. It will allow you to select an option, and when you press the button it will generate the popup message and return the value of selected radio button. In the following image, you can observe the output of the above code.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); radioButton1.Image = Image.FromFile("C:\\Users\\Jade\\Pictures\\brownImage.jpg"); } } }
First Method | Second Method |
---|---|
using System; using System.Drawing; using System.Windows.Forms; namespace strnull { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { radioButton1.BackColor = Color.AliceBlue; } private void radioButton1_BackColorChanged(object sender, EventArgs e) { MessageBox.Show("BackColor is changed to " + radioButton1.BackColor.ToString()); } } }In the above code, when the background color of the radio button is changed. Message prompt with the name of color which is set as the background. In the following image, you can observe the output of the above code.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radioButton1_CheckedChanged(object sender, EventArgs e) { MessageBox.Show("Option changed."); } } }In the above code, we have used two radio button. Whenever you will change the radio buttons value or option CheckedChanged event gets executed. In the below image you can observe the output
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radioButton1_Click(object sender, EventArgs e) { MessageBox.Show("You Clicked!"); } } }In the above code, we have used two radio buttons and just added the click event to the first radio button. If you will click the radio button1 then you will observe the popup message but if you clicked in the radio button2 then nothing will happen except that radio button2 get selected. It's because we have added the Click event just for the radio button1. In the following image, you can observe the output of above code.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { radioButton1.ForeColor = Color.BlueViolet; } private void radioButton1_ForeColorChanged(object sender, EventArgs e) { MessageBox.Show("ForeColor Is changed to " + radioButton1.ForeColor.ToString()); } } }In the above code, we have set the ForeColor ti BlueViolet when user will click the button. Then ForeColorChanged Event executed and prompt the message which color is selected as the ForeColor. In the following image, you can observe the output of the above code.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radioButton1_MouseHover(object sender, EventArgs e) { MessageBox.Show("Mouse Hover to " + radioButton1.Text.ToString()); } } }In the above code, we have set the prompt message when user will hover the first radio button. You can declare any kind of functionality which you want to perform. In the following Image, you can be observed the output.
using System; using System.Drawing; using System.Windows.Forms; namespace strnull { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radioButton1_MouseHover(object sender, EventArgs e) { MessageBox.Show("Mouse Hover to " + radioButton1.Text.ToString()); } private void radioButton1_MouseLeave(object sender, EventArgs e) { MessageBox.Show("Mouse Left " + radioButton1.Text.ToString()); } } }In the above code, you cab observed the MouseHover and MouseLeave both events. When user will hover the mouse a prompt message show that user is hover mouse cursor on radiobutton1 and when a user left the radiobutton1 boundaries its show prompt message again. In the below image you can observe the output of above code.
using System; using System.Drawing; using System.Windows.Forms; namespace TEP { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { radioButton1.Text = "New Text"; } private void radioButton1_TextChanged(object sender, EventArgs e) { MessageBox.Show("Radio Button Text changed to " + radioButton1.Text.ToString()); } } }You can observe in the above code, there are two events. The button click event changed the text of radio button and TextChanged event get executed when text gets changed. In the following image, you can be observed the output. You also observed that when button event is executed radio button text doesn't change but the value is set to new text. After the execute of textChanged Event, it's get changed. It's because all the events have same priority or execution, so first events get executed then their effects applied.
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w