How to pass textbox data between two forms?

后端 未结 3 715
旧巷少年郎
旧巷少年郎 2021-01-28 14:14

How to send textbox value to textbox between two forms without Show()/ShowDialog() by button? I want to textBox will get value without open form.

3条回答
  •  我在风中等你
    2021-01-28 14:48

    I don't know what exactly you mean by saying "without Show()/ShowDialog()", but that is not relevant anyway or I'll just assume here further that you have both windows open (doesn't matter how you accomplished that).

    You would like to avoid much coupling between two forms, especially not implementation details like a textbox etc. You could work with delegates and events to trigger the "sending" of data between your two forms. You can then easily pass event data and your subscribed other form (or any other object as a matter of fact) doesn't know the exact implementation details of your form, it only knows the data it will receive through the delegate (event). I am not going to post all code here, because it is already nicely explained at following URL: http://www.codeproject.com/Articles/17371/Passing-Data-between-Windows-Forms .

提交回复
热议问题