show dialog just after a form is shown

L

lukasz

Is there an equivalent of OnShow event for forms? I want to open a file open
dialog immediately after my form is shown (modelessly). OnLoad and
OnVisibleChanged do not suit me since it shows the file dialog before
showing my form. Any ideas?
 
I

Imran Koradia

try the Activated Event of the form. This is fired after the Load event when
the form is activated. Ofcourse, this is also fired when the form is
activated from an inactive state. So you'll probably need to check whether
its the first time Activated has been fired (after the Load).

hope this helps..
Imran.
 
M

Mark Broadbent

One way to do this is to use event delegates.
Create your procedure to show your dialog. Subscribe this to the event of
your choice (for this example I used the paint event) within the Form Load.
Within your procedure you should unsubscribe itself from the paint event so
that the dialog is only shown once.

as thus...
private void FormLukazExample_Load(object sender, System.EventArgs e)
{
this.Paint +=new PaintEventHandler(OpenFileDialog);
}

private void OpenFileDialog(object sender, PaintEventArgs p)
{
this.Paint -= new PaintEventHandler(OpenFileDialog);
System.Windows.Forms.OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
//code
}
}

Hope this helps :)
Br,

Mark Broadbent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top