Home >Backend Development >C++ >How Can I Change a Control on One Windows Form from Another?
When using multiple windows in Windows Forms applications, you may need to operate controls on different windows. Here are some methods to implement this task:
The control on the window B from the window A:
Construct function parameters:
Define a constructor in the window B, which accepts the appropriate parameter of the value you want to set.
When creating an instance of the window B from the window A, the value required by constructing a function can be passed by constructing a function.Create public attributes or methods in window B to allow you to operate specific controls. After creating an instance of the window B, use these attributes/methods to set or retrieve the value.
This allows you to use its name to access the control directly from the window A (similar to visiting any other public members).
Create a public method or attribute in the window A, which accepts the window instance as a parameter.
In the window B, use the instance of the pass to operate the control on the window A.
The incident in the window B is caused by the operation required for the execution of the window A.
Public control:
In the designer of the window B, set the "modifier" property of the control to "public", and ensure that "generators" are true.
These are just several ways to communicate between the windows. The best way depends on the specific needs of the application.<code class="language-csharp">public Form2(int value) { // ... this.comboBox1.SelectedValue = value; }</code>
The above is the detailed content of How Can I Change a Control on One Windows Form from Another?. For more information, please follow other related articles on the PHP Chinese website!