Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are referencing <code>testButton1</code> like it was a static field instead of an instance field. You need to be able to access the instance of the form. You can do this like this:</p> <pre><code>public partial class Form1 : Form { public static Form1 Instance { get; private set; } public Form1() { InitializeComponent(); if (Instance != null) throw new Exception("Only one instance of Form1 is allowed"); Instance = this; FormClosed += new FormClosedEventHandler(Form1_FormClosed); } void Form1_FormClosed(object sender, FormClosedEventArgs e) { Instance = null; } public Button TestButton1 { get { return testButton1; } } } </code></pre> <p>Because controls on the form are protected by default, you have to make the button accessible. You do this using the <code>TestButton1</code> property.</p> <p>Now you can access the textbox using <code>BElite.Form1.Instance.TestButton1</code>.</p> <p>Two notes:</p> <ol> <li><p>This only works if you always have a single <code>Form1</code>, for example when <code>Form1</code> is the main form of your application;</p></li> <li><p>Please note that accessing these controls from a different thread must be done using <code>Control.Invoke()</code> or <code>Control.BeginInvoke()</code>. See the documentation on these methods on why and how.</p></li> </ol> <p>You can access the button using <code>BeginInvoke()</code> with the following sample:</p> <pre><code>Form1.Instance.BeginInvoke(new Action(() =&gt; { Form1.Instance.TestButton1.Text = "My new text"; })); </code></pre> <p>Everything in the block (<code>{ ... }</code>) is safe.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload