Show function

  • Thread starter Thread starter Xavier PACOTTE
  • Start date Start date
X

Xavier PACOTTE

Hello,

I would like to add some actions to show function of a form with Visual
Stuio 2005.
Is it possible?
Is it possible to create a new Show function which inherit of old it?

Best Regards.
 
Perhaps overriding OnLoad() might be more appropriate; what are you
trying to do?

Marc
 
Hello,

I would like to add some actions to show function of a form with Visual
Stuio 2005.
Is it possible?
Is it possible to create a new Show function which inherit of old it?

Best Regards.

Dear Xavier,

You can override the OnShown method or use the Shown event.

What exactly you want to achieve?

Moty
 
public class FormEx : Form
{
public new void Show()
{
//do your pre-stuff
base.Show();
//do your post-stuff
}

public new void Show(IWin32Window owner)
{
//do your pre-stuff
base.Show(owner);
//do your post-stuff
}
}

Xavier PACOTTE je napisao/la:
 
thank you for this answer.
it is ok.

Miroslav Stampar said:
public class FormEx : Form
{
public new void Show()
{
//do your pre-stuff
base.Show();
//do your post-stuff
}

public new void Show(IWin32Window owner)
{
//do your pre-stuff
base.Show(owner);
//do your post-stuff
}
}

Xavier PACOTTE je napisao/la:
 
Warning - this will only work if the caller knows about FormEx; if the
caller only knows about Form, then the original Show will be called,
and your code will not be executed.

As such, this is *not* recommded best-practice. The OnLoad / OnShown
methods (and matching events) are far more reliable.

Marc
 
public class FormEx : Form
{
public new void Show()
{
//do your pre-stuff
base.Show();
//do your post-stuff
}

public new void Show(IWin32Window owner)
{
//do your pre-stuff
base.Show(owner);
//do your post-stuff
}
}

Xavier PACOTTE je napisao/la:

Hi,

I wouldn't suggest using this solution since it's not polymorphic.

The following code will not do what you need:

Form frm = new Form1();
frm.Show();

Only if frm is of type Form1, the Form1 implementation of Show() will
be called.

Moty
 

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

Back
Top