Variables Access

J

Jim Shady

Hi,

I am primarily a Borland Delphi developer and I'm very new to C#
(using VS.NET). Here is my problem:

I have three forms:

frmLogin
frmMain
frmChgPass

After the user authenticates himself in frmLogin, it's visble property
is turned off and the main form shows. In the Main form I have a
button which the user can click to open to change his password.

I need to retrieve the logged in username from frmLogin. How do I
access it from frmChgPass? How do I declare it in frmLogin?

Thank you for you help in advance.

Jim
 
M

Morten Wennevik

Hi Jim,

These are only a few thoughts:
If it's only the username you need you can make it a property and pass the
instance of frmLogin to frmMain when you create it. Then have frmMain use
frmLogin.UserName when needed.
Or, you can pass the username in the constructor when creating frmMain.
Or, you can have frmMain, notify frmLogin that the user wants to change
the password, and have frmLogin create frmChgPass and pass the username in
the constructor.
Or... quite a few possibilities to solve your problem.

The username member of frmLogin should remain private, but you can expose
it in a read only property (one with only get{}. I would probably pass it
in the constructor instead of using a property, and let frmMain store it
in it's own private member, which frmMain in turn can pass on to
frmChgPass when needed.

Hope this helps!
Morten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top