Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, I still don't know much about your use case, but I'll take a stab anyway, and provide a simple example.</p> <p>I assume that you want to control something on the main form from your floating form. To do this, you need a reference to your main form from your floating form. You do this by creating a constructor overload in your floating form that accepts an instance of your main form, like this:</p> <pre><code> public FloatingForm(MainForm mainForm) { InitializeComponent(); _mainForm = mainForm; } </code></pre> <p>The floating form contains a textbox named floatingFormTextBox, and a button named Button1. The partial class for the floating form looks like this:</p> <pre><code>public partial class FloatingForm : Form { MainForm _mainForm; public FloatingForm() { InitializeComponent(); } public FloatingForm(MainForm mainForm) { InitializeComponent(); _mainForm = mainForm; } private void button1_Click(object sender, EventArgs e) { _mainForm.DoSomething(floatingFormTextBox.Text); } } </code></pre> <p>The main form just contains a textbox named mainFormTextBox. When the main form loads, it creates an instance of the floating form, passing a reference to itself to the floating form's new constructor overload. The partial class for the main form looks like this:</p> <pre><code>public partial class MainForm : Form { FloatingForm _floatingForm; public MainForm() { InitializeComponent(); } public void DoSomething(string text) { mainFormTextBox.Text = text; this.Refresh(); } private void MainForm_Load(object sender, EventArgs e) { _floatingForm = new FloatingForm(this); _floatingForm.Show(); } } </code></pre> <p>Now, when I put some text into the textbox of the floating form and click the button, the text shows up in the textbox of the main form.</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