Search code examples
c#buttontextboxlabelsubform

C# Get information from a form (Like MessageBox buttons just with a form made by me)


recenntly I've been working on a painting software,
and i need to get information from a sub-form that contain's 3 controls:

  • TextBox1 - a TextBox
  • OkButton - a Button
  • CancelButton - a Button

the main form contains 2 controls:

  • Label1 - a Label
  • ChangeLabel1TextButton - a Button

That sub-form need to be shown when i press the "ChangeLabel1TextButton" button on my main-form,
than, when you press the "OkButtom" on the sub-form,
the main form need's to set "Label1" text to the text of "TextBox1" textbox on the sub-form.

Images of the forms:

-The forms

The forms

-What the forms supposed to do

What the forms supposed to do

Hope you could help me!
Thanks anyway : )


Solution

  • To get you started,

    1. In your sub-form, create a public property (let's call it InputText) that returns the text of the textbox.
    2. In your main-form, open the sub-form (.ShowDialog())
    3. After the sub-form has closed (close it when OK is pressed), use the new property (InputText) to get the text and set to your label.Text.
    4. Done!