Results 1 to 18 of 18

Thread: Form Enable and Disable

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    63

    Form Enable and Disable

    How it work when form1.enabled =false; form2.show() while form2 open.when form2 is close form1 will be enable.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Form Enable and Disable

    don't use .show .... use .ShowDialog instead.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    63

    Re: Form Enable and Disable

    how about when i hide the form how can i return it to show?

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Form Enable and Disable

    Yes.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Form Enable and Disable

    Quote Originally Posted by solid2005 View Post
    how about when i hide the form how can i return it to show?
    Hey,

    If you use Show.Dialog, there really isn't any need to hide the first form. Using ShowDialog means that the user can no longer access Form 1. Give it a try, and you will see what we mean.

    Gary

  6. #6
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Form Enable and Disable

    indeed. ShowDialog is best practice in terms of design but also user experience. you should never hide one form and show another. whilst its possible to do this, and can provide code, it is highly not recommended to do this.

    furthermore, say for example your application is expecting some response from somewhere but form1 or form2 is hidden - how do you expect the application to exit or even display the form because of a coding bug that was undiscovered?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    63

    Re: Form Enable and Disable

    can give me example that focus on second form? not using ShowDialog on form2. i just use function of focus(). for form2.

  8. #8
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Form Enable and Disable

    it is highly advisable not to do what you are doing.

    Modify the constructor of Form2 to take in Form1 instance and store it in a global private variable.

    Code:
    private Form1 mainForm;
    
    public Form2(Form1 parentForm)
    {
       InitializeComponent();
       this.mainForm = parentForm;
    }
    then in Form1 when you are doing to show form2, do this:

    Code:
    ..
    ..
    
    Form2 secondForm = new Form2(this);
    secondForm.Show();
    this.Hide();

    then in form2 when you want to go back to the previous form, do this:

    Code:
    this.Hide();
    this.mainForm.Show();

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    63

    Re: Form Enable and Disable

    new problem i run the same time of the form try my upload. i can't use topmost because of when alt+tab.
    why code i will use.
    Attached Files Attached Files

  10. #10
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Form Enable and Disable

    sorry i dont understand. does this new problem have any relevance to the code given? if so and you are wanting to switch forms - you wont be able to because you are hiding a form and showing another form which is one of many reasons why you shouldnt be doing it this way

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    63

    Re: Form Enable and Disable

    can be use focus? insted of showdialog?

  12. #12
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Form Enable and Disable

    why do you want to do that?

    if a form is hidden, you cannot view it unless you call the Show() method on that form instance.

    what are you trying to do? why can you not use ShowDialog? why are you avoiding to use this correct method?

    please explain in detail what you are trying to achieve and why.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    63

    Re: Form Enable and Disable

    no i just run 2 form in the same time example my form1 is already show then i add on form1_load
    form2 _form2 = form2();
    _from2.show();

    the form2 always at the back of the form1

  14. #14
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Form Enable and Disable

    solid,

    I think you need to take a step back here.

    Write down the exact requirements of what you are trying to do, i.e. what forms are visible and which ones aren't and at which point. What causes these things to happen? How you want the user to interact with the forms? etc.

    Once we have all of the requirements, then the best overall recommendation can be provided.

    I would also suggest that you look at some of the existing applications that you use already on your computer, i.e. Word, Visual Studio. Do these applications do the type of things that you are asking for? If not, then you might want to think about why you want to go against the grain. These applications will have invested hundreds of thousands of pounds/dollars trying to get the UI to be the best that they are, and you have to think they are doing things that way for a reason.

    Gary

  15. #15

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    63

    Re: Form Enable and Disable

    i made from vb.net example. not using Showdialog() and topmost
    Attached Files Attached Files

  16. #16

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    63

    Re: Form Enable and Disable

    how to convert to C#?

  17. #17
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Form Enable and Disable

    post the code

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  18. #18
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Form Enable and Disable

    There are a number of online converters that will be able to help you convert your VB.Net Code to C#. For instance:

    http://www.developerfusion.com/tools.../vb-to-csharp/

    Gary

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