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?
Imran Koradia - 30 Aug 2004 18:39 GMT
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.
> 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?
Mark Broadbent - 01 Sep 2004 11:21 GMT
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.
> 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?