473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

NOOB Alert: Windows Forms in c#

Hi all,

I am writing a little application. The main form presents a main menu
and within this menu there is an "options" part. This option will show
a new form, where some application settings can be made. When the user
presses on the OK button, I need the changed information in my main
form, so the code can act upon the (possible) changes made.

So what I do is: I instantiate the form, I show the form, data gets
changed, but how do I get the data back? Both forms are totally
different. I know how to pass data TO the form, but I need data FROM
the form. The only solution I know off, is to create a class for my
"set of options" and pass that object to the second form. I think there
is an easier way...

can anybody help me out here?

TIA

Richard

Nov 17 '05 #1
2 1707
rs********@gmail.com wrote:
Hi all,

I am writing a little application. The main form presents a main menu
and within this menu there is an "options" part. This option will show
a new form, where some application settings can be made. When the user
presses on the OK button, I need the changed information in my main
form, so the code can act upon the (possible) changes made.

So what I do is: I instantiate the form, I show the form, data gets
changed, but how do I get the data back? Both forms are totally
different. I know how to pass data TO the form, but I need data FROM
the form. The only solution I know off, is to create a class for my
"set of options" and pass that object to the second form. I think there
is an easier way...

can anybody help me out here?

TIA

Richard

There are a number of ways you could do this.
You could put a public property on the form and set >> show >> get this
property.

I normally do it like this.
1. Overload ShowDialog and pass in a ref to your object.
2. On dialogresult.ok (in your form), update the object and all is good.

Cheers
JB
Nov 17 '05 #2
Well, I found a way to do it, that I think is nice and OO based...

The mainform will containt the code to act upon the settings made in
the options form. So, I have create a struct (rather then a class,
since it's (so far) only data and no methods) that contains all the
options settings.

So in mainform I have private variables that in the end will contain
the settings as thay are made in the struct.
I instantiate the struct in the mainform.
Then I launch the options form
Instantiate the struct here too.
Then when the form has the settings that the user needs, I pass them to
the struct.
Close the form
In the mainform I then feed my private variables with the data in the
struct.

Now all I need to do is write the code to actually act upon it (validty
checks are done in the form where the data is entered, so the data that
I will work with is ok).

Is this a good way to do it?

Regards,

Richard

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bf | last post by:
I was creating test projects using c# and was surprised that there seems to be only a form based windows applications available. Is it safe to assume that classic window applications that utilize a...
1
by: William Sullivan | last post by:
I've spent plenty of time building windows forms, but I'm working on a web project now. I've scanned a few ASP NET books, checked out some tutorials, but I am unable to figure out how to lay out...
2
by: Rick | last post by:
I have VS2005 solution containing a console app project plus a lot of projects it depends on. When I compile the solution, only those dlls that are directly referenced are copied to the console app...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
4
by: yawnmoth | last post by:
I'm trying to display a popup showing which radio button is selected and am unable to do so. Every time I try, I get undefined, instead of the value of the particular form variable I'm trying to...
3
by: Luc The Perverse | last post by:
Hey - I am making my first C# form application! (More a teach myself app than any pratical application) I have a listbox that always has the control so I made an event handler for KeyDown. I...
4
by: Mel Smith | last post by:
Hi: I am a programmer (but in a language that is compiled into C code -- then onto .obj and and then an executable -- xHarbour) I already am able to (programmatically) visit websites, and read...
2
by: Tom P. | last post by:
I'm not getting the theory behind LINQ, and without that I can't get my head around how to use it and why. Here's what I _think_ I'm trying to do: I've got a menu with several items. Some other...
20
by: Peter | last post by:
I need a popup alert after a post back. 1) user clicks on the submit button 2) Server side code runs and if the result is false I want to display a java script alert("It did not work") How to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.