Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2005, 03:52 AM
Authorized User
 
Join Date: Mar 2005
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing variables between forms

I'm new to programming windows applications in .NET.

I have a very simple application, about the same complexity as notepad.exe. In the menu I have a Settings item which opens a new Form. There I have a few textboxes, radiobuttons and such.

I want these settings to be accessable from every form in my project. Obviously I can not directly read the TextBox.Text value from a different form than the settings form.

How do I declare these variables where I want to store settings data?
How do I pass these variables to different forms?

In the Settings Form I have a OK and a Cancel button. If the user clicked Cancel I do not want the changed fields to have changed the settings variabels.

Thanks in advance...

 
Old July 11th, 2005, 09:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Well, first - there are several ways that you can directly read the text from a textbox on a different form, depending on what you want to do.

If it is accessing a parent form from a child form, the parent form will need to be instantiated. Then you just have to create a public textbox object and then set your textbox equal to this. You can then access all of that textboxes methods and properties.

Another way would be to create a constructor in your child form that allows you to pass in the form that you want to access. This will let you access all of that forms methods and properties, assuming that they are of the correct scope.

If it is a child form that you want to access, you can simply access the text properties of the particular textbox when you instantiate the form using something like: frm.TextBox1.Text where frm is current instance of your child form.

-------------------------------------

However, if it is settings that you want to use in your application, there are a couple of ways of doing this.

You can either read/write these to the registry, a database, an xml file, a text file, etc. If you did this, you wouldn't have to worry about passing these variables among forms. There is probably no best choice for these, all have certain benefits so just choose the best solution for you.

J





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Variables CMOS Classic ASP Basics 2 January 22nd, 2006 07:38 PM
Simple 'passing variables between forms' issue... overture C# 4 October 14th, 2005 02:30 PM
Passing variables jesseleon Access VBA 4 October 24th, 2003 01:45 PM
Forms and variables Dai Beginning PHP 4 June 19th, 2003 02:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.