Results 1 to 11 of 11

Thread: I hate it so much!

  1. #1

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

    Question I hate it so much!

    If anyone is able to do that, please reply:

    1. Create a new form in your project and set it as the
    startup form.

    2. Add a second form that can be used as dialog.

    3. Add a button to the dialog form and then do the following:

    When the application starts, the startup form should
    call the dialog form to be shown on the screen.
    During this, the startup form has to be disabled for a while.

    The second form has a button and if you click it, it should
    enable the first form and close the dialog.

    Can anybody do that in C# or VB.NET?

    thx!

  2. #2
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327

    It's easy

    Make the two forms with VS.net. Create the dialog form in the constructor of the main form, before InitializeComponent is called, and show it with the ShowDialog method. When your dialog is done, just call the close method on it, and the program will continue as usual. If you need feedback from the dialog, you will have to create a public property that the main form can read once the dialog is closed.
    PHP Code:
    // Constructor of primary form (startup)
    public MainForm()
    {
       
    // Create the dialog and show it.
       
    TestDialog MyDialog = new TestDialog();
       
    MyDialog.ShowDialog();

       
    //
       // Required for Windows Form Designer support
       //
       
    InitializeComponent();
        

    -scott
    he he he

  3. #3

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

    I need to disable the Main form and
    when the dialog closes, the Main form
    should be enabled again.

    'MainForm.Enabled = False' ?

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try this

    this.Hide();
    Dont gain the world and lose your soul

  5. #5

    Thread Starter
    Hyperactive Member vbzero's Avatar
    Join Date
    Aug 2000
    Location
    Vienna
    Posts
    347
    this only works for the current form - not for another form

  6. #6

    Thread Starter
    Hyperactive Member vbzero's Avatar
    Join Date
    Aug 2000
    Location
    Vienna
    Posts
    347
    I can't understand why this is so a big problem - in VB 6
    this was always possible - what the hell have they done?

  7. #7
    Addicted Member donut's Avatar
    Join Date
    Mar 2001
    Location
    London, UK
    Posts
    165
    i have a similar problem, in that i have a form that loads another form, but if i try to unload the first form from the second form, it unloads the entire project!

  8. #8

    Thread Starter
    Hyperactive Member vbzero's Avatar
    Join Date
    Aug 2000
    Location
    Vienna
    Posts
    347
    How do you try to unload the first form?

    (in code)

  9. #9
    Addicted Member donut's Avatar
    Join Date
    Mar 2001
    Location
    London, UK
    Posts
    165
    well, actually i just had a brief memory lapse, that wasn't quite what i meant. if i try to load the second form, and then unload the first form, it unloads the project, like this:

    Code:
    Form2 frm = new Form2
    frm.Show
    this.Dispose(True)
    but that is a good question, how would you unload a form from another form...

  10. #10
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If I understand you correctly, you want to show form2 as modal form:
    PHP Code:
    private void Form1_Load(object senderSystem.EventArgs e)
    {
        
    this.Show();
        
    this.Activate();
        
    Form2 frm = new Form2();
        
    //notice [b]this[/b] object is being passed to the ShowDialog method. This parameter defines the owner
        //this will make the Form2 as modal
        
    frm.ShowDialog(this);


  11. #11
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    I'm not sure what the big deal is. Maybe we're not understanding the problem...

    You should be able to do this in several ways. You can either use the ShowDialog like Serge and I suggested, which automatically disables the first form (easiest way).

    Or, you can declare the second form as a private variable in the class. Then, show it non-modally (.Show) and hide the current form after it is shown (This.Hide). In order to show the main form after the dialog is closed, simply respond to the dialog form's Closed event.

    If this doesn't solve the problem, can you better explain it for us?
    -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