Eddie Lascu <[EMAIL PROTECTED]> wrote:

> The way I understand this is that even if I re-instantiate the class that
> implements my form, the framework will reuse some previously created
> structures and that's how I would explain why the Load event is not fired
> for subsequent calls to ShowDialog.

This isn't true for re-instantiated forms. Here's how I typically show
dialogs:

---8<---
using System;
using System.Windows.Forms;

class MyDialog : Form
{
    public MyDialog()
    {
        Load += delegate { MessageBox.Show("Load!"); };
        ShowInTaskbar = false;
        Text = "Dialog";
    }
    
    public static bool EditFoo(IWin32Window owner)
    {
        using (MyDialog dialog = new MyDialog())
        {
            // dialog.SetUp(); or whatever
            bool result = dialog.ShowDialog(owner) == DialogResult.OK;
            if (result)
            {
                // dialog.CollectInfo(); or whatever
            }
            return result;
        }
    }
}

class App
{
    static void Main()
    {
        Form form = new Form();
        form.Text = "Main";
        form.Click += delegate
        {
            MyDialog.EditFoo(form);
        };
        Application.Run(form);
    }
}
--->8---

If you compile and run this application, you'll see that the Load event
gets raised every time the form is created.

Sending the owner in to the ShowDialog() method is important if you want
to avoid situations where the dialog can get lost behind other windows
etc.

EditFoo is typically named to something that the dialog is editing, and
some Foo would be passed to EditFoo() along with the parent.

-- Barry

-- 
http://barrkel.blogspot.com/

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to