please have a look at the following code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace calc
{
public partial class Form1 : Form
{
//code removed
public Form1()
{
InitializeComponent();
calculator = new Calculator();
maleRadio.PerformClick();
englishRadio.PerformClick();
}
/*code removed*/
//Action Listener for Female Radio button
private void femaleRadio_CheckedChanged(object sender, EventArgs e)
{
//code removed
}
//Action Listener for English Radio button
private void englishRadio_CheckedChanged(object sender, EventArgs e)
{
//code removed
}
}
}
I am somewhat new to c#. what I want to do here is to trigger the event handlers
of radio buttons inside the constructor programatically. The way I followed maleRadio.PerformClick();
do nothing. how can I call the event handlers inside the constructor programmertically ?
You can call the event handlers like any other method:
public Form1()
{
InitializeComponent();
calculator = new Calculator();
maleRadio_CheckedChanged(maleRadio, null);
englishRadio_CheckedChanged(englishRadio, null);
}
You can just call the function femaleRadio_CheckedChanged
on your constructor. Or you can set the value of the selected index of the radiobutton to trigger the event:
femaleRadio_CheckedChanged(null, null);
or
femaleRadio.SelectedIndex = 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With