Reputation: 45
Ok so
i have 2 form lets call them main and second forms
On main there is nothing but a textbox(lets call it T1) which is PUBLIC so it supposed to be reachable from any form.
On second there is nothing but a textbox(T2) which is public, and a button(pub)(call it B)
On the codes, there is nothing in main
On the codes of second there is
public string s1
and in codes of button B:
s1 = T2.Text;
MAIN mainredirect = new MAIN();
MAIN.T1.Text = s1;
and thats it. what i am doing wrong?
p.s: there is no error that shown by vs, so its not syntax error
Upvotes: 2
Views: 3628
Reputation: 12652
Don't understand what you trying to achieve, but probably you forget to simply Show()
created form.
EDIT:
Readed your comments. As i understand your main form opens second form like a dialog and you want to get entered value from it.
Code for your main form will be:
private void callSecondFormButton_Click(object sender, EventArgs e)
{
SecondForm second = new SecondForm();
second.ShowDialog();
mainFormTextBox.Text = second.Result;
}
For your second form:
public string Result = string.Empty;
private void secondFormCloseButton_Click(object sender, EventArgs e)
{
Result = secondFormTextBox.Text;
Close();
}
callSecondFormButton - button on the main form that calls your second form; mainFormTextBox - text box on your main form; SecondForm - your second form that will be called from main; Result - public field of second form for retrieving result of entering text; secondFormCloseButton - button on the second form that will update Result and close dialog.
In the main form need first to create second form instance and show form. After executing ShowDialog
main form will wait for closing opened form. After closing it will retrieve resulted text.
Upvotes: 1
Reputation: 67345
Is this WinForms? It's a little hard to tell what you are trying to do. Have you stepped through with a debugger? Is the string getting set? How are you confirming it is not? Is it because the form is not yet loaded?
You are showing only snippets. It should be very easy for you to further isolate this using the debugger.
Upvotes: 0