You should check your UI view code for example XAML , Razor , HTML ,... and make sure they are in the same group.
Are you observing this behavior, if you are not using above code?
In addition, you may use the object name , so instead of this.Checked
you may try RadioButton1 for example and set it to be checked or not.
Custom Radio Button C#
Hemanth B
886
Reputation points
Hi I created a custom radio button in WinForms.
The problem is this:
As you may know, if a radio button is checked, then the other radio buttons under the same parent control are unchecked automatically.
This is the source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace Test
{
class MTARadioButton : System.Windows.Forms.RadioButton
{
public MTARadioButton()
{
lb.BringToFront();
lb.Text = "";
lb.Font = new Font("Segoe Fluent Icons", 16, FontStyle.Regular);
lb.Click += Lb_Click;
this.Controls.Add(lb);
this.CheckedChanged += CustomCheckBox_CheckedChanged;
}
private string _text = "MTACheckBox1";
public string RadioButtonText
{
get { return _text; }
set
{
_text = value;
lb2.Text = _text;
}
}
Label lb2 = new Label();
private void CustomCheckBox_CheckedChanged(object? sender, EventArgs e)
{
if (this.Checked == false)
{
lb.ForeColor = Color.Black;
lb.Text = "";
}
else
{
lb.ForeColor = Color.DodgerBlue;
lb.Text = "";
}
}
Label lb = new Label();
private void Lb_Click(object? sender, EventArgs e)
{
lb.ForeColor = Color.DodgerBlue;
lb.Text = "";
}
}
}
Developer technologies C#
11,570 questions
2 answers
Sort by: Most helpful
-
Reza-Ameri 17,336 Reputation points Volunteer Moderator
2022-02-13T16:40:30.657+00:00 -
Karen Payne MVP 35,586 Reputation points Volunteer Moderator
2022-02-13T17:52:45.44+00:00