title: Windows Form Application Radio Button
body: <p>it is my first time asking here. there is some kind of bug in my program where if i click the rbUnderline the label1 will be underlined but if i click another rb let's say rbBold(obv. the label will become bold) then click the rbUnderline the label wont be underlined again.</p>
  
  <p>here is my code:</p>
  
  <pre><code>public Form1()
          {
              InitializeComponent();
          }
  
          private void radioButton1_CheckedChanged(object sender, EventArgs e)
          {
  
              if (rbBold.Checked == true)
              {
                  label1.Font = new Font(label1.Font, FontStyle.Bold);
              }
              else if (rbItalic.Checked == true)
              {
                  label1.Font = new Font(label1.Font, FontStyle.Italic);
              }
              else if (rbUnderline.Checked == true)
              {
                  label1.Font = new Font(label1.Font, FontStyle.Underline);
              }
  
  
  
  
  
          }
  </code></pre>
  
  <p>Designed.cs Code</p>
  
  <pre><code>namespace WindowsFormsApplication1
  {
      partial class Form1
      {
          /// &lt;summary&gt;
          /// Required designer variable.
          /// &lt;/summary&gt;
          private System.ComponentModel.IContainer components = null;
  
          /// &lt;summary&gt;
          /// Clean up any resources being used.
          /// &lt;/summary&gt;
          /// &lt;param name="disposing"&gt;true if managed resources should be disposed; otherwise, false.&lt;/param&gt;
          protected override void Dispose(bool disposing)
          {
              if (disposing &amp;&amp; (components != null))
              {
                  components.Dispose();
              }
              base.Dispose(disposing);
          }
  
          #region Windows Form Designer generated code
  
          /// &lt;summary&gt;
          /// Required method for Designer support - do not modify
          /// the contents of this method with the code editor.
          /// &lt;/summary&gt;
          private void InitializeComponent()
          {
              this.label1 = new System.Windows.Forms.Label();
              this.rbBold = new System.Windows.Forms.RadioButton();
              this.rbItalic = new System.Windows.Forms.RadioButton();
              this.rbUnderline = new System.Windows.Forms.RadioButton();
              this.SuspendLayout();
              // 
              // label1
              // 
              this.label1.AutoSize = true;
              this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
              this.label1.Location = new System.Drawing.Point(58, 65);
              this.label1.Name = "label1";
              this.label1.Size = new System.Drawing.Size(158, 25);
              this.label1.TabIndex = 0;
              this.label1.Text = "SAMPLE TEXT";
              // 
              // rbBold
              // 
              this.rbBold.AutoSize = true;
              this.rbBold.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
              this.rbBold.Location = new System.Drawing.Point(15, 20);
              this.rbBold.Name = "rbBold";
              this.rbBold.Size = new System.Drawing.Size(66, 28);
              this.rbBold.TabIndex = 1;
              this.rbBold.TabStop = true;
              this.rbBold.Text = "Bold";
              this.rbBold.UseVisualStyleBackColor = true;
              this.rbBold.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
              // 
              // rbItalic
              // 
              this.rbItalic.AutoSize = true;
              this.rbItalic.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
              this.rbItalic.Location = new System.Drawing.Point(87, 20);
              this.rbItalic.Name = "rbItalic";
              this.rbItalic.Size = new System.Drawing.Size(64, 28);
              this.rbItalic.TabIndex = 2;
              this.rbItalic.TabStop = true;
              this.rbItalic.Text = "Italic";
              this.rbItalic.UseVisualStyleBackColor = true;
              // 
              // rbUnderline
              // 
              this.rbUnderline.AutoSize = true;
              this.rbUnderline.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
              this.rbUnderline.Location = new System.Drawing.Point(157, 20);
              this.rbUnderline.Name = "rbUnderline";
              this.rbUnderline.Size = new System.Drawing.Size(110, 28);
              this.rbUnderline.TabIndex = 3;
              this.rbUnderline.TabStop = true;
              this.rbUnderline.Text = "Underline";
              this.rbUnderline.UseVisualStyleBackColor = true;
              this.rbUnderline.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
              // 
              // Form1
              // 
              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
              this.ClientSize = new System.Drawing.Size(270, 104);
              this.Controls.Add(this.rbUnderline);
              this.Controls.Add(this.rbItalic);
              this.Controls.Add(this.rbBold);
              this.Controls.Add(this.label1);
              this.Name = "Form1";
              this.Text = "Form1";
              this.ResumeLayout(false);
              this.PerformLayout();
  
          }
  
          #endregion
  
          private System.Windows.Forms.Label label1;
          private System.Windows.Forms.RadioButton rbBold;
          private System.Windows.Forms.RadioButton rbItalic;
          private System.Windows.Forms.RadioButton rbUnderline;
      }
  }
  </code></pre>