ControlBuilder.InDesigner 属性

定义

返回 ControlBuilder 是否正在设计器中运行。

protected:
 property bool InDesigner { bool get(); };
protected bool InDesigner { get; }
member this.InDesigner : bool
Protected ReadOnly Property InDesigner As Boolean

属性值

Boolean

如果 ControlBuilder 正在设计器中运行,则为 true;否则为 false

示例

以下示例在调用该方法时NeedsTagInnerText使用InDesigner该属性。 当控件附加此生成器时,该方法 NeedsTagInnerText 确定控件是否在设计时通过设计器访问该控件。 返回 NeedsTagInnerText 属性的值 InDesigner ,然后 SetTagInnerText 调用该方法。 如果属性 InDesigner 设置为 false,则会引发一个 Exception 。 否则,在调用时 SetTagInnerText 返回控件的内部文本。

[AspNetHostingPermission(SecurityAction.Demand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class MyControlControlBuilder : ControlBuilder
{
    private string _innerText;

    public override bool NeedsTagInnerText()
    {
        return InDesigner;
    }

    public override void SetTagInnerText(string text)
    {
        if (!InDesigner)
            throw new Exception("The control is not in design mode.");
        else
            _innerText = text;
    }
}
<AspNetHostingPermission(SecurityAction.Demand, _
  Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class MyControlControlBuilder
  Inherits ControlBuilder
    
    Private _innerText As String
    
    Overrides Public Function NeedsTagInnerText() As Boolean
      Return InDesigner
    End Function
    
    Overrides Public Sub SetTagInnerText(ByVal text As String)        
       If InDesigner = False
         Throw New System.Exception("The control is not in design mode.")
       Else
         _innerText = text
       End If
    End Sub
    
End Class

适用于