Instantiate a form

G

Guest

I am loading a form in this method. I have an accessor that is called Loginstatus within the frmMainForm. When I Instantiate the frmMainForm I want to disable the File Menu if the Loginstatus is false. In VB6 I would do something like this
frmMainForm auth = new frmMainForm()
auth.Loginstatus = fals

However, in C# when I execute frmMainForm auth = new frmMainForm(); the InitializeComponent routine is triggered. I understand that you are not suppose to edit this code? If thats the case then where is the best place to check for the Loginstatus value to see whether the File menu should be enabled or not. Currently I have this checking the Load event of the form
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?U1BTU0c=?= said:
frmMainForm auth = new frmMainForm();
auth.Loginstatus = false

However, in C# when I execute frmMainForm auth = new frmMainForm();
the InitializeComponent routine is triggered. I understand that you are
not suppose to edit this code? If thats the case then where is the best
place to check for the Loginstatus value to see whether the File menu
should be enabled or not.

In the constructor, directly after the call to 'InitializeComponent'.
 
G

Guest

Usin
frmMainForm auth = new frmMainForm()
auth.Loginstatus = fals

My problem is when putting mnuFile.Enabled = false directly after the 'InitializeComponent' is that the auth.Loginstatus = false hasn't executed yet. I need to set this accessor to true or false before I enable/disable the File Menu.
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?U1BTU0c=?= said:
Using
frmMainForm auth = new frmMainForm();
auth.Loginstatus = false


My problem is when putting mnuFile.Enabled = false directly after the
'InitializeComponent' is that the auth.Loginstatus = false hasn't
executed yet. I need to set this accessor to true or false before I
enable/disable the File Menu.

Then add the code to the form's 'OnLoad' method or 'Load' event handler.
 
R

Rigga

Also if LoginStatus is a property.. you could always add code to the Set
method to enable / disable the file menu when LoginStatus is set.. that way
whenever Loginstatus is set the file menu is always enabled / disabled.

Jus my two cents worth..HTH.

Rigga.

SPSSG said:
Using
frmMainForm auth = new frmMainForm();
auth.Loginstatus = false


My problem is when putting mnuFile.Enabled = false directly after the
'InitializeComponent' is that the auth.Loginstatus = false hasn't executed
yet. I need to set this accessor to true or false before I enable/disable
the File Menu.
 

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