11,579 questions
Create an event, for example checked changed on a CheckBox.
public partial class UserControl1 : UserControl
{
public delegate void OnCheckChanged(CheckBox sender);
public event OnCheckChanged OnCheckChangedEvent;
public UserControl1()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
OnCheckChangedEvent?.Invoke((CheckBox)sender);
}
}
Subscribe in the form to the event above
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DemoControl.OnCheckChangedEvent += DemoControlCheckChanged;
}
private void DemoControlCheckChanged(CheckBox sender)
{
MessageBox.Show($"{sender.Checked}");
}
}
Or change the Modifiers property
of the control, in this case a CheckBox from private to public than directly subscribe to the event. This is not recommended, always scope to the smallest needs possible.