accessing form controls from another class c#
public partial class Form1 : Form
{
//https://stackoverflow.com/questions/12983427/accessing-forms-controls-from-another-class
// Static form. Null if no form created yet.
private static Form1 form = null;
private delegate void EnableDelegate(bool enable);
public Form1()
{
InitializeComponent();
form = this;
}
// Static method, call the non-static version if the form exist.
public static void EnableStaticTextBox(bool enable)
{
if (form != null)
form.EnableTextBox(enable);
}
private void EnableTextBox(bool enable)
{
// If this returns true, it means it was called from an external thread.
if (InvokeRequired)
{
// Create a delegate of this method and let the form run it.
this.Invoke(new EnableDelegate(EnableTextBox), new object[] { enable });
return; // Important
}
// Set textBox
textBox1.Enabled = enable;
}
}
Also in C#:
- dynamic convert type c#
- c# keyvaluepair
- unity reset scene
- string.insert c#
- uinput dialog uwp c#
- regex replace all special characters
- findobject getcomponent
- c# how to add newline on text box
- c# EncoderParameter
- fieldconverter c#
- how to trigger event when a com device is connected in c#
- how to name GameObject in c#
- c# add object to array
- c# sort for loop
- c# list tuple
- c# implement a superclass in subclass
- change z value unity
- how to access the dictionary from another script in unity
- unity round vector 3 to nearest integer
- how to change text to bold through script unity
- unity delete specific text in a string
- c# transform
- how to work with ascii in c#
- add row and columns to grid wpf in code