.NET Framework Developer Center > .NET Development Forums > .NET Base Class Library > How could I determine am I in design-time or run-time in my code when using Inheritance
Ask a questionAsk a question
 

AnswerHow could I determine am I in design-time or run-time in my code when using Inheritance

  • Wednesday, November 04, 2009 9:15 PMA.Aziem Moemen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have 2 Windows Forms named (FrmBase, FrmRegularForm)

    FrmRegularForm inherits FrmBase

    FrmBase contains FrmBase_Load event handler :
        MessageBox.Show("TEST");

    When I open  FrmRegularForm in design-time --> FrmBase_Load fires  and I believe that it's RIGHT

    Now, I want to preent this action @ design-time

    I NEED IT IN RUN-TIME ONLY

    Any suggestion is appreciated.

Answers

  • Wednesday, November 04, 2009 10:19 PMJaedenRuiner Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    All descendants of System.ComponentModel.Component (which includes System.Windows.Forms.Control, and thus subsequently System.Windows.Forms.Form) all contain a Protected property: DesignMode

    thus:

    public sub FrmBase_Load(sender as object, e as EventArgs) handles me.Load
      If Not MyBase.DesignMode then
          MesageBox.Show("Test")
      end if
    End Sub

    Cheers
    Jaeden "Sifo Dyas" al'Raec Ruiner

    "Never Trust a computer. Your brain is smarter than any micro-chip."

All Replies

  • Wednesday, November 04, 2009 10:19 PMJaedenRuiner Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    All descendants of System.ComponentModel.Component (which includes System.Windows.Forms.Control, and thus subsequently System.Windows.Forms.Form) all contain a Protected property: DesignMode

    thus:

    public sub FrmBase_Load(sender as object, e as EventArgs) handles me.Load
      If Not MyBase.DesignMode then
          MesageBox.Show("Test")
      end if
    End Sub

    Cheers
    Jaeden "Sifo Dyas" al'Raec Ruiner

    "Never Trust a computer. Your brain is smarter than any micro-chip."