ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Writing to Form1 textbox from Form2

<< < (2/3) > >>

kyrathaba:
In the short term, passing form instances around to constructors and whatnot will work, but it's not good for modularity, re-use, or being able to comprehend your code a few months from now.

The first thing you need to learn is separating your GUI from your "real code". This means having pretty much all your logic separated from the GUI code, and never directly referencing GUI controls from the logic/model code. Let your GUI controls observe your program's model state, and let GUI events be very shallow things doing little else but delegating to instance calls on your model.
--- End quote ---

Agreed.  :Thmbsup:

Renegade:
Here's another way to do things... Keep in mind that is not appropriate for some things, but depending upon your logic, it can function perfectly fine with much less code.

Use settings. Done.

e.g.


--- Code: C# ---// Set itProperties.Settings.Default.SomeTypedValue = myvar; // Get itmynewvar = Properties.Settings.Default.SomeTypedValue;
You can do that from anywhere in the application.

But, like I said, it's not appropriate all the time. It makes sense in some situations though.

It's kind of abusing the settings, but whatever. If you're careful about what you're doing, it's an incredibly cheap and fast hack to get the job done.

wraith808:
It's kind of abusing the settings, but whatever.
-Renegade (December 04, 2011, 07:31 AM)
--- End quote ---

I think I just threw up a little in my mouth. ;)

It creates a large window of exposure, and debugging anything that occurred from that (other than in the simplest case) is going to be a nightmare, IMO.

Renegade:
It's kind of abusing the settings, but whatever.
-Renegade (December 04, 2011, 07:31 AM)
--- End quote ---

I think I just threw up a little in my mouth. ;)

It creates a large window of exposure, and debugging anything that occurred from that (other than in the simplest case) is going to be a nightmare, IMO.
-wraith808 (December 04, 2011, 07:02 PM)
--- End quote ---

Not really... Like I said, if the situation is appropriate, then it's ok. Like in the simplest cases. :)

Here's an example.

You have FORM1 where you enter a value then store it. Later, you open FORM2, but need that value. You simply then retrieve it and handle the situation if the value isn't present. The key being that if the value isn't present when you open FORM2, then you should avoid it.

If you need to programmatically create values with both forms open, then it's a bad idea.

Basically, if you need a timer, it's a bad idea and a cheap hack that you should only use for prototyping.


wraith808:
^ OK.  I can go with that. :)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version