Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 21st, 2009, 09:13 AM
Registered User
Points: 37, Level: 1
Points: 37, Level: 1 Points: 37, Level: 1 Points: 37, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to z2g007
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.
Reply With Quote
  #2 (permalink)  
Old November 7th, 2009, 12:46 PM
Authorized User
Points: 100, Level: 1
Points: 100, Level: 1 Points: 100, Level: 1 Points: 100, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #3 (permalink)  
Old December 13th, 2009, 09:08 AM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
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;
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Professional Windows GUI Programming using C# Blackadder All Other Wrox Books 2 February 11th, 2011 09:27 AM
device DLL programming in client side programming hendyhanusin ASP.NET 1.0 and 1.1 Professional 2 February 19th, 2009 11:01 AM
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 12:44 PM



All times are GMT -4. The time now is 11:52 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.