-
Nasty objects in C#
Code:
frmNickname nick = new frmNickname();
nick.Show();
Isn't this stupid? This is since J++.
Is there no way to show the form object only?
Do I always have to create a new instance of the object?
The show property isn't supported unless I do this.
This could bring you in troubles:
Let's say you have a MainForm and this form shows a
new one (maybe a dialog). Perhaps you want to disable
the MainForm so that only the new form is enabled.
What would you do when you want to re-enable the first
form?
The "enabled" property is not show unless you create a
new instance of the base MainForm.
But if you do this, a new instance will first be created and
then enabled but not the first MainForm.
You can try to write a function:
Code:
public static bool Enable(bool Value)
{
// ... Code for enabling or disabling the form comes here
}
This code will need the "this" object, but this is not allowed
in static methods.
Crazy! Isn't it?
Any ideas how to prevent this?
thx!
-
here is what you do guy
you make a class called
CMyForms
and you instantiate objects in this class
and you can use one object of this class through out your forms that contains your other forms
-
Will this help in the case of dialogs or do I not understand what you are saying?
Code:
frmNickname nick = new frmNickname();
nick.ShowDialog();
-
OK - now you have created a new instance of a form...
The MainForm should be disabled:
MainForm.Enabled = False
After this you close the new instance created before and
then the MainForm should be re-enabled.
-
vbzero, this is actualy the correct way to instanciate an object. In VB6 and earlier it was done by VB behind the scenes.
I really like the idea that you now have to do it the right way. :)
-
I thought using showdialog to show a form disabled the parent form?
-