Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

How to make programmatically created radiobutton enable by a button click.

$
0
0
public Form1()
        {
            InitializeComponent();

            var drvs = System.IO.DriveInfo.GetDrives();
            int hdcount = 0;
            List<string> drivenames = new List<string>();
            foreach (var drv in drvs)
            {
                if (drv.DriveType == System.IO.DriveType.Fixed)
                {
                    drivenames.Add(drv.Name);
                    hdcount++;
                }
            }

            int locy = 41;
            for (int i = 0; i < hdcount; i++)
            {
                RadioButton rdbtn = new RadioButton();
                rdbtn.Name = "rdbtn" + i.ToString();
                rdbtn.CheckedChanged += new EventHandler(rdbtn_CheckedChanged);
                rdbtn.Location = new System.Drawing.Point(12, locy);
                rdbtn.Text = drivenames[i].Replace("\\", "");
                rdbtn.Enabled = false;
                this.Controls.Add(rdbtn);
                locy += 23;
            }

I use this code to add radio buttons to my code for a program. All those radio buttons must be disabled at the beginning. I want to make them enable when user clicked the button1. 

rdbtn.Enabled = true; code does not work because those radiobuttons have been created programmatically. 

How can I do this ?


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>