Yes. Just create these members with public visibility and access the other form.
You can change the visibility of the form controls in the box properties (the same as where the name, text, etc. of the components is changed) and the modifiers for public
It is also possible to change the file. Form designer, however, is not a good idea since this code is written by Visual Studio, so it may end up being rewritten if some visual modification is made to these components.
public MacroForm()
{
InitializeComponent();
var motorForm = new MotorForm();
var potencia = motorForm.txtPotencia.Text;
//Desde que txtPotencia seja public, isso é válido
}
If you don’t want to directly expose the controls of form as Textboxes, etc. It is possible to create public methods (or getters and setters) to change these values
However, keep in mind that the more components are "shared" the more code will need to be written in this case. Quite possible that all this code is useless if the real need is just to recover/settar values for the controls.
Just so I understand, inside
MotorForm
has the 3TextBox
, and you need to recover byMacroForm()
? first you open theMacroForm
and right after theMotoForm()
?– novic
That’s right @Virgilionovic
– Raphael Prado de Oliveira