Wrox Programmer Forums
|
Book: C# 2008 Programmer's Reference ISBN: 978-0-470-28581-7
This is the forum to discuss the Wrox book C# 2008 Programmer's Reference by Wei-Meng Lee; ISBN: 9780470285817
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Book: C# 2008 Programmer's Reference ISBN: 978-0-470-28581-7 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 October 21st, 2009, 09:13 AM
Registered User
 
Join Date: Oct 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Windows Programming in C#

Hi there,
How can I create a variable in Windows form which can be used to hold the User-name of the user and can be accessed throughout the application.
 
Old November 7th, 2009, 01:46 PM
Authorized User
 
Join Date: Nov 2009
Posts: 26
Thanks: 1
Thanked 1 Time in 1 Post
Default

Hi

You can define a global variable(I mean define a variable at the beginning of the form's class before all other methods and after the openning brace) and initialize it to null.Then if your application have a button to save the username you can add such a code to the button's click event:
userName=textboxUserName.text;
If your application does not contain such a button,never mind,add the same code to the textbox's TextChanged event.This way,the moment text changed in textbox,it is directly stored in userName.

Hope that hepls..

Erfan
 
Old December 13th, 2009, 10:08 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

you should create a static and public class in a separate file (because of avoiding nested classes) like this

Code:
public static class MyVariables
{
   public static string Username {get; set; }
}
and you can set MyVariables.Username = "some username"; and access it like:
string username = MyVariables.Username;





Similar Threads
Thread Thread Starter Forum Replies Last Post
Professional Windows GUI Programming using C# Blackadder All Other Wrox Books 2 February 11th, 2011 10:27 AM
device DLL programming in client side programming hendyhanusin ASP.NET 1.0 and 1.1 Professional 2 February 19th, 2009 12:01 PM
Windows Mobile 6 programming yukijocelyn C# 2005 0 May 7th, 2008 02:33 AM
Where to learn C++ Windows Programming Cris987 C++ Programming 1 December 28th, 2003 01:44 PM





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