共用方式為


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

範例

下列範例會在 InDesigner 呼叫 方法時 NeedsTagInnerText 使用 屬性。 當控制項附加這個產生器時, NeedsTagInnerText 方法會決定控制項是否在設計階段透過設計工具存取。 會 NeedsTagInnerText 傳回 屬性的值 InDesigner ,然後 SetTagInnerText 呼叫 方法。 InDesigner如果 屬性設定為 falseException 則會擲回 。 否則,會在呼叫時 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

適用於