I want to use the controls of a form from a generic class. In VB is very easy but in C# is difficult as I am trying to learn it. So searching I found an ease answer to this and I am coping here
Set the control to public in the designer:
public System.Windows.Forms.Button button1;
Create a new class and for example rename it to exampleClass
public class exampleClass
{
public static Form1 frm;
public static void HideButton()
{
frm.button1.Visible = false;
}
}
Add this after Form1 InitializeComponent:
exampleClass.frm = this;
Now you can hide the button from anywhere you want:
exampleClass.HideButton();
My question now is: If we want to make more general and pass the control and the status (true/false) to the class method eg
exampleClass.HideButton(Control, Status)
How can we do?
Thanks in advance, Elias