PC Review


Reply
Thread Tools Rate Thread

Access form controls from another form

 
 
Paez
Guest
Posts: n/a
 
      29th Dec 2006
Hi there.

How can I modify a form control property from another form. Let's say, I
have a frmMain that has a ToolStripMenuItem with the current user info.
Then, I open another form (frmChangeUser) and after I enter a password in
that form, the current user will change and the frmMain ToolStripMenuItem
will also change.

Right now, I have the folowing code:

frmChangeUser:----------------------
(...)
frmMain.CurrentUser = "Administrator";
frmMain.Administrator();
(...)


frmMain:---------------

public static void Administrador()
{
frmMain x = new frmMain();

x.tssUser.Text = CurrentUser;
}

Any help? Thanks in advance...

Paez


 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      29th Dec 2006
It depends on whether frmChangeUser is modal or not. If it is modal,
just have some properties on frmChangeUser, and after ShowDialog()
simply read them and update. The next preferred option (regardless of
modality) is to have some event(s); at the simplest:

public event EventHandler UserChanged;

on frmChangeUser which you hook from frmMain (immediately after
creating the form), and in the handler you again read the properties
you expose. You can do the same with a custom event signature
(eventargs), but it is extra work for little gain. Another (slightly
messier) way is to pass the frmMain instance to frmChangeUser (for
instance in the ctor), but this is not very reusable, and is against
best practice; the OO principle here is that frmChangeUser knows about
users (and changing them), and frmMain knows about the menu; let
frmMain update itself when frmChangeUser does something note-worthy.

Does that make sense?

Marc

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access all controls on ASP.Net form pargat.singh@gmail.com Microsoft Dot NET 1 29th Jun 2007 02:43 AM
Access form controls =?Utf-8?B?c211ZGdl?= Microsoft Access 1 7th Feb 2006 04:43 AM
How can i access form controls in VB.NET Mamatha Microsoft VB .NET 1 2nd Dec 2004 08:20 AM
Access ALL controls on a form? Jamie Fraser Microsoft Dot NET 2 1st Sep 2004 01:00 PM
Re: MS Access form Controls Albert D. Kallal Microsoft Access 0 15th Aug 2004 03:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:33 PM.