Results 1 to 7 of 7

Thread: Nasty objects in C#

  1. #1

    Thread Starter
    Hyperactive Member vbzero's Avatar
    Join Date
    Aug 2000
    Location
    Vienna
    Posts
    347

    Question 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!

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    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

  3. #3
    BG
    Guest
    Will this help in the case of dialogs or do I not understand what you are saying?

    Code:
     frmNickname nick = new frmNickname();
    	nick.ShowDialog();

  4. #4

    Thread Starter
    Hyperactive Member vbzero's Avatar
    Join Date
    Aug 2000
    Location
    Vienna
    Posts
    347
    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.

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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.

  6. #6
    BG
    Guest
    I thought using showdialog to show a form disabled the parent form?

  7. #7
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    it does
    -scott
    he he he

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width