![]() |
|
[C#] Form Communication Questions - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] Form Communication Questions (/showthread.php?tid=5842210) |
Form Communication Questions - PH_Trick - May 29, 2018 I am Korean. Writes through Google Translator. The program I'm writing is tcp communication. I opened "B Form" in "A Form". ("A Form" -> "B Form") I want to send and receive commands from "B Form" but I do not know what to do. This is the current way. 1. In "A form", click button and wait. 2. Client requests are processed according to the request value. (There is a separate class file for waiting and processing the request.) RE: Form Communication Questions - Dalvik - May 29, 2018 Depending on what you want to update this can be done in multiple wayse. If you want to for example update a listbox or listview or something on the other form, you can use databinding and pass a reference to a bindinglist to another form. Or you can use custom events. Whatever you want. RE: Form Communication Questions - PrivateOctopus - May 29, 2018 I didn't understand it quite well. but seems hard. RE: Form Communication Questions - Esteban - May 29, 2018 .. the a form is just a control panel ? and b form is the one that will send data? you said you created class, then just create new instance on the b form. RE: Form Communication Questions - Dalvik - May 29, 2018 (May 29, 2018 07:46 AM)Esteban Wrote: .. Or pass a reference to the class in the constructor of the B form. RE: Form Communication Questions - Esteban - May 29, 2018 (May 29, 2018 07:48 AM)Dalvik Wrote: Or pass a reference to the class in the constructor of the B form. .. may do, as i think he will need to pass the id of the client on the b form for it to send the data. a form (button) then after clicing button, b form show and the b form containing controls like open zipper, do back flip, etc. RE: Form Communication Questions - 0xDEAD10CC - May 30, 2018 (May 29, 2018 07:48 AM)Dalvik Wrote: Or pass a reference to the class in the constructor of the B form. Not the way to do it. If someone at a bank deposits a cheque for you do they let you go to the back and have access to everything so you can deposit it yourself? Custom events, or dependency injection is a much better way. You want to be passing around data or references that only pertain to what you need. Packaging the data and sending it as an object to the constructor would be cleaner. This way if you needed 2-way manipulation the other side can re-receive the data after it has been manipulated. RE: Form Communication Questions - Dalvik - May 30, 2018 (May 30, 2018 11:24 AM)0xDEAD10CC Wrote: Not the way to do it. If someone at a bank deposits a cheque for you do they let you go to the back and have access to everything so you can deposit it yourself? I find this analogy very weird, but I get what you mean. This can be solved with an interface though. RE: Form Communication Questions - 0xDEAD10CC - May 30, 2018 (May 30, 2018 01:28 PM)Dalvik Wrote: I find this analogy very weird, but I get what you mean. This can be solved with an interface though. An interface is for contracts, this is data, so it wouldn't make sense in this case. I'm talking more about an IoC container. The point I was trying to give, is that the whole point of encapsulation is to only give access to things that you want something else to have. By passing the form reference, you're giving that other object to change everything. RE: Form Communication Questions - Dalvik - May 30, 2018 (May 30, 2018 01:30 PM)0xDEAD10CC Wrote: An interface is for contracts, this is data, so it wouldn't make sense in this case. I'm talking more about an IoC container. The point I was trying to give, is that the whole point of encapsulation is to only give access to things that you want something else to have. By passing the form reference, you're giving that other object to change everything. I never meant give a reference to a whole form to another form. Also, what you said I already (partially) said before: (May 29, 2018 07:08 AM)Dalvik Wrote: Depending on what you want to update this can be done in multiple wayse. If you want to for example update a listbox or listview or something on the other form, you can use databinding and pass a reference to a bindinglist to another form. Or you can use custom events. Whatever you want. RE: Form Communication Questions - 0xDEAD10CC - May 30, 2018 (May 30, 2018 01:35 PM)Dalvik Wrote: I never meant give a reference to a whole form to another form. I did read that, but what I was quoting was this: "Or pass a reference to the class in the constructor of the B form" |