c# access form function from another class code example
Example: accessing form controls from another class c#
public partial class Form1 : Form
{
private static Form1 form = null;
private delegate void EnableDelegate(bool enable);
public Form1()
{
InitializeComponent();
form = this;
}
public static void EnableStaticTextBox(bool enable)
{
if (form != null)
form.EnableTextBox(enable);
}
private void EnableTextBox(bool enable)
{
if (InvokeRequired)
{
this.Invoke(new EnableDelegate(EnableTextBox), new object[] { enable });
return;
}
textBox1.Enabled = enable;
}
}