[VB.NET]Detect Design-Time & Run-Time

[VB.NET]Detect Design-Time & Run-Time


Introduction

在撰写控件时,我们常会需要依照不同的阶段作不同的处理。像是在设计阶段显示与运行阶段不同的画面、关闭些在设计阶段会造成错误的处理等等。这边将对侦测目前所处阶段的语法作些整理。

Detect Design-Time & Run-Time

若要在程序中分辨设计phase(Design-Time)与运行phase(Run-Time),我们大致上有以下几种方法。

WinForm

1.判断Component.DesignMode


2.判断Site.DesignMode


3.判断当前处理序是否为Visual Studio


4.判断LicenseUsageMode.UsageMode是否为LicenseUsageMode.Designtime


5.判断GetService(GetType(System.ComponentModel.Design.IDesignerHost))不为空


ASP.NET

请参阅Detecting Designmode in ASP.Net

WPF

请参阅Detecting design time mode in WPF and Silverlight

Link

  • How Do I Detect Design-Time Vs Run-Time in a .NET Control?

  • Identifying the Run-Time and the Design Mode

  • Design Time Detection

  • Detect if Code is Running from the IDE

  • Detecting Design-time in C#

  • Windows Forms designer and DesignMode property issues

  • MSDN - Component.DesignMode Property

  • MSDN - IDesignerHost 界面

  • Detecting Designmode in ASP.Net

  • Detecting design time mode in WPF and Silverlight