語言

WebPartDesigner 類別

定義

提供設計時的視覺化控制支援 WebPart 。

public ref class WebPartDesigner : System::Web::UI::Design::WebControls::WebParts::PartDesigner
public class WebPartDesigner : System.Web.UI.Design.WebControls.WebParts.PartDesigner
type WebPartDesigner = class
    inherit PartDesigner
Public Class WebPartDesigner
Inherits PartDesigner
繼承

範例

以下程式碼範例展示了控制項與其對應WebPart的 之間的互動WebPartDesigner。 控制 WebPart 項包含 Calendar 一個控制項,供最終使用者選擇生日,一個 Button 用來提交選擇的控制項,以及 Label 一個顯示使用者生日訊息的控制項。 該控制器 WebPartDesigner 會驗證所屬控制的類型是否符合預期類型,並自訂該控制點的設計時渲染方式。 請注意,設計師的視覺自訂僅在設計時可見,而相關控制項的自訂則在執行時與設計時皆可見。

本範例中覆寫的所有方法皆源自基 ControlDesigner 底類別。 關於其他可用成員及其使用情況,請參見 System.Web.UI.Design.ControlDesigner。

using System;
using System.Security.Permissions;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.Design.WebControls.WebParts;
using System.ComponentModel;

/// <summary>
/// BirthdayPart demonstrates some of the most
/// common overrides of members of the WebPart
/// class. BirthdayPartDesigner shows how to 
/// customize the rendering of a custom WebPart
/// control.
/// </summary>
namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  [Designer(typeof(BirthdayPartDesigner))]
  public class BirthdayPart : WebPart
  {
    private DateTime birthDate;
    Calendar input;
    Label displayContent;

    public BirthdayPart()
    {
      this.AllowClose = false;
      this.Title = "Enter your birthday";
    }

    [
      Personalizable(PersonalizationScope.User, true),
      WebBrowsable()
    ]
    public DateTime BirthDate
    {
      get { return birthDate; }
      set { birthDate = value; }
    }
    
    // Set the appearance of the control at run time.
    protected override void CreateChildControls()
    {
      Controls.Clear();
      input = new Calendar();
      this.Controls.Add(input);
      Button update = new Button();
      update.Text = "Submit";
      update.Click += new EventHandler(this.submit_Click);
      this.Controls.Add(update);
      displayContent = new Label();
      displayContent.BackColor = 
      System.Drawing.Color.LightBlue;
      Literal br = new Literal();
      br.Text = "<br />";
      if ((this.birthDate.Day == DateTime.Now.Day)
        && (this.birthDate.Month == DateTime.Now.Month))
      {
        displayContent.Text = "Happy Birthday!";
        this.Controls.Add(br);
        this.Controls.Add(displayContent);
      }
    }

    private void submit_Click(object sender, EventArgs e)
    {
      this.birthDate = input.SelectedDate;
    }
  }

  public class BirthdayPartDesigner : WebPartDesigner
  {
    public override void Initialize(IComponent component)
    {
      // Verify that the associated control is a BirthdayPart.
      if (!typeof(BirthdayPart).IsInstanceOfType(component))
      {
        throw new ArgumentException("The specified control is not of type 'BirthdayPart'", "component");
      }
      base.Initialize(component);
    }

    // Here is where you make customizations
    // to design time appearance that will not
    // be visible to the end user.
    public override string GetDesignTimeHtml()
    {
      string designTimeHtml = null;
      try
      {
        designTimeHtml = base.GetDesignTimeHtml();
        string s = "<hr /><hr />I just added these lines to the"
          + " bottom of the control.<hr /><hr /></div>";
        designTimeHtml = designTimeHtml.Replace("</div>", s);
      }
      catch (Exception ex)
      {
        designTimeHtml = GetErrorDesignTimeHtml(ex);
      }
      finally
      {
        // undo any changes in the try block
      }

      if ((designTimeHtml == null) || (designTimeHtml.Length == 0))
      {
        designTimeHtml = GetEmptyDesignTimeHtml();
      }
      return designTimeHtml;
    }

    // This method normally returns a blank string.
    // Override to return a meaningful message.
    protected override string GetEmptyDesignTimeHtml()
    {
      return CreatePlaceHolderDesignTimeHtml(
        "<hr />If the page developer forgot to fill in a " +
        "required property you could tell them here.<hr />");
    }
    
    // Add specific text to the generic error message.
    protected override string GetErrorDesignTimeHtml(Exception e)
    {
      string s = "<hr />The control failed to render.";
      return(s + e.Message + "<hr />");
    }
  }
}
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.Design.WebControls.WebParts
Imports System.ComponentModel

' BirthdayPart demonstrates some of the most
' common overrides of members of the WebPart
' class. BirthdayPartDesigner shows how to 
' customize the rendering of a custom WebPart
' control.
Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    <Designer(GetType(BirthdayPartDesigner))> _
    Public Class BirthdayPart
        Inherits WebPart
        Private m_birthDate As DateTime
        Private input As Calendar
        Private displayContent As Label

        Public Sub New()
            Me.AllowClose = False
            Me.Title = "Enter your birthday"
        End Sub

        <Personalizable(PersonalizationScope.User, True), WebBrowsable()> _
        Public Property BirthDate() As DateTime
            Get
                Return m_birthDate
            End Get
            Set(value As DateTime)
                m_birthDate = value
            End Set
        End Property

        ' Set the appearance of the control at run time.
        Protected Overrides Sub CreateChildControls()
            Controls.Clear()
            input = New Calendar()
            Me.Controls.Add(input)
            Dim update As New Button()
            update.Text = "Submit"
            AddHandler update.Click, New EventHandler(AddressOf Me.submit_Click)
            Me.Controls.Add(update)
            displayContent = New Label()
            displayContent.BackColor = System.Drawing.Color.LightBlue
            Dim br As New Literal()
            br.Text = "<br />"
            If (Me.m_birthDate.Day = DateTime.Now.Day) AndAlso (Me.m_birthDate.Month = DateTime.Now.Month) Then
                displayContent.Text = "Happy Birthday!"
                Me.Controls.Add(br)
                Me.Controls.Add(displayContent)
            End If
        End Sub

        Private Sub submit_Click(sender As Object, e As EventArgs)
            Me.m_birthDate = input.SelectedDate
        End Sub
    End Class

    Public Class BirthdayPartDesigner
        Inherits WebPartDesigner
        Public Overrides Sub Initialize(component As IComponent)
            ' Verify that the associated control is a BirthdayPart.
            If Not GetType(BirthdayPart).IsInstanceOfType(component) Then
                Throw New ArgumentException("The specified control is not of type 'BirthdayPart'", "component")
            End If
            MyBase.Initialize(component)
        End Sub

        ' Here is where you make customizations
        ' to design time appearance that will not
        ' be visible to the end user.
        Public Overrides Function GetDesignTimeHtml() As String
            Dim designTimeHtml As String = Nothing
            Try
                designTimeHtml = MyBase.GetDesignTimeHtml()
                Dim s As String = "<hr /><hr />I just added these lines to the" & " bottom of the control.<hr /><hr /></div>"
                designTimeHtml = designTimeHtml.Replace("</div>", s)
            Catch ex As Exception
                designTimeHtml = GetErrorDesignTimeHtml(ex)
                ' undo any changes in the try block
            Finally
            End Try

            If (designTimeHtml Is Nothing) OrElse (designTimeHtml.Length = 0) Then
                designTimeHtml = GetEmptyDesignTimeHtml()
            End If
            Return designTimeHtml
        End Function

        ' This method normally returns a blank string.
        ' Override to return a meaningful message.
        Protected Overrides Function GetEmptyDesignTimeHtml() As String
            Return CreatePlaceHolderDesignTimeHtml("<hr />If the page developer forgot to fill in a " & "required property you could tell them here.<hr />")
        End Function

        ' Add specific text to the generic error message.
        Protected Overrides Function GetErrorDesignTimeHtml(e As Exception) As String
            Dim s As String = "<hr />The control failed to render."
            Return (s & e.Message & "<hr />")
        End Function
    End Class
End Namespace

備註

該 WebPartDesigner 類別在設計時提供控制項的視覺化表示 WebPart 。 它是從 PartDesigner 類別衍生出來的,並加入驗證以驗證所屬控制是否為 WebPart 控制或衍生型別。

WebPartDesigner 從 UsePreviewControl 父節點繼承一個屬性,該屬性總是設為 true。 這會使視覺設計環境產生 View 一個控制項,暫時保存在設計表面上的 副本 WebPart ;這個副本接著會被持久化成標記。 如果你覆寫屬性 UsePreviewControl 返回 false,視覺設計環境會直接從實際 WebPart 控制項產生標記。

網頁零件設計師通常與一般控制設計師類似;設定設計時外觀的主要方法源自該 ControlDesigner 類別。 具體來說,你可以覆寫 GetDesignTimeHtml 改變控制點設計時標記的方法。 你也可以覆寫 GetErrorDesignTimeHtml 和 GetEmptyDesignTimeHtml 方法,分別處理錯誤和空字串(「」)。

建構函式

名稱 Description
WebPartDesigner()

初始化 WebPartDesigner 類別的新執行個體。

屬性

名稱 Description
ActionLists

取得控制設計器的動作清單集合。

(繼承來源 ControlDesigner)
AllowResize

會獲得一個值,表示控制項是否能在設計時環境中調整大小。

(繼承來源 ControlDesigner)
AssociatedComponents

取得設計師管理的與該元件相關的元件集合。

(繼承來源 ComponentDesigner)
AutoFormats

取得預設自動格式化方案集合,於設計時顯示於相關控制項的 自動格式 化對話框中。

(繼承來源 ControlDesigner)
Behavior
已淘汰.

取得或設定與設計器相關的 DHTML 行為。

(繼承來源 HtmlControlDesigner)
Component

取得設計師正在設計的元件。

(繼承來源 ComponentDesigner)
DataBindings

取得目前控制項的資料綁定收集。

(繼承來源 HtmlControlDesigner)
DataBindingsEnabled

取得一個值,表示相關控制項的包含區域是否支援資料綁定。

(繼承來源 ControlDesigner)
DesignerState

取得一個物件,用於在設計時持久化相關控制項的資料。

(繼承來源 ControlDesigner)
DesignTimeElement
已淘汰.

取得代表該物件在設計表面上所關聯 HtmlControlDesigner 控制項的設計時物件。

(繼承來源 HtmlControlDesigner)
DesignTimeElementView
已淘汰.

取得控制設計器的視控物件。

(繼承來源 ControlDesigner)
DesignTimeHtmlRequiresLoadComplete
已淘汰.

會取得一個值,表示設計主機是否必須完成載入才能呼叫該 GetDesignTimeHtml 方法。

(繼承來源 ControlDesigner)
Expressions

在設計時取得目前控制項的表達式綁定。

(繼承來源 HtmlControlDesigner)
HidePropertiesInTemplateMode

會取得一個值,表示當控制項處於模板模式時,相關控制項的屬性是否被隱藏。

(繼承來源 ControlDesigner)
ID

取得或設定控制項的 ID 字串。

(繼承來源 ControlDesigner)
InheritanceAttribute

會獲得一個屬性,表示相關元件繼承的類型。

(繼承來源 ComponentDesigner)
Inherited

會得到一個值,表示該元件是否為繼承。

(繼承來源 ComponentDesigner)
InTemplateMode

會獲得一個值,表示控制項在設計主機中是處於範本檢視模式還是編輯模式。 該 InTemplateMode 屬性為唯讀。

(繼承來源 ControlDesigner)
IsDirty
已淘汰.

取得或設定一個值,表示網頁伺服器控制項是否被標記為變更。

(繼承來源 ControlDesigner)
ParentComponent

取得這個設計器的父元件。

(繼承來源 ComponentDesigner)
ReadOnly
已淘汰.

取得或設定一個值,表示控制項屬性在設計時是否為唯讀。

(繼承來源 ControlDesigner)
RootDesigner

取得包含相關控制項的網頁表單頁面的控制項設計器。

(繼承來源 ControlDesigner)
ShadowProperties

會取得一組屬性值,覆蓋使用者設定。

(繼承來源 ComponentDesigner)
ShouldCodeSerialize
已淘汰.

在序列化過程中,會取得或設定一個值,指示是否要在目前設計文件的程式碼背後檔案中為控制項建立欄位宣告。

(繼承來源 HtmlControlDesigner)
Tag

取得一個代表相關控制項 HTML 標記元素的物件。

(繼承來源 ControlDesigner)
TemplateGroups

獲得一組模板群組,每個群組包含一個或多個範本定義。

(繼承來源 ControlDesigner)
UsePreviewControl

會獲得一個值,指示設計師是否應該使用暫存複製品,而非與設計師實際相關的控制項來產生設計時標記。

(繼承來源 PartDesigner)
Verbs

取得與設計者相關元件所支援的設計時動詞。

(繼承來源 ComponentDesigner)
ViewControl

取得或設定一個網頁伺服器控制項,可用於預覽設計時的 HTML 標記。

(繼承來源 ControlDesigner)
ViewControlCreated

取得或設定一個值,指示是否 View 已建立控制項以顯示於設計表面。

(繼承來源 ControlDesigner)
Visible

會獲得一個值,表示該控制點在設計時是否可見。

(繼承來源 ControlDesigner)

方法

名稱 Description
CreateChildControls()

建立這個 CompositeControl 控制的子控制。

(繼承來源 CompositeControlDesigner)
CreateErrorDesignTimeHtml(String, Exception)

建立 HTML 標記,在設計時顯示指定的例外錯誤訊息。

(繼承來源 ControlDesigner)
CreateErrorDesignTimeHtml(String)

建立 HTML 標記,在設計時顯示指定的錯誤訊息。

(繼承來源 ControlDesigner)
CreatePlaceHolderDesignTimeHtml()

提供簡單的矩形佔位符號表示,顯示控制項的類型與 ID。

(繼承來源 ControlDesigner)
CreatePlaceHolderDesignTimeHtml(String)

提供簡單的矩形佔位符號表示,顯示控制項的類型與 ID,以及額外指定的指令或資訊。

(繼承來源 ControlDesigner)
CreateViewControl()

回傳相關控制項的副本,用於在設計表面上檢視或渲染。

(繼承來源 ControlDesigner)
Dispose()

釋放 ComponentDesigner所使用的所有資源。

(繼承來源 ComponentDesigner)
Dispose(Boolean)

釋放物件使用的 HtmlControlDesigner 非管理資源,並可選擇性地釋放受管理資源。

(繼承來源 HtmlControlDesigner)
DoDefaultAction()

在原始碼檔案中為元件的預設事件建立方法簽章,並引導使用者游標到該位置。

(繼承來源 ComponentDesigner)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetBounds()

取得代表控制點邊界的矩形座標,該矩形在設計表面上顯示。

(繼承來源 ControlDesigner)
GetDesignTimeHtml()

取得設計時用來表示控制項的 HTML。

(繼承來源 CompositeControlDesigner)
GetDesignTimeHtml(DesignerRegionCollection)

取得 HTML 標記以顯示控制項,並將目前控制項設計區域填充集合。

(繼承來源 ControlDesigner)
GetEditableDesignerRegionContent(EditableDesignerRegion)

回傳可編輯區域中可編輯的相關控制項。

(繼承來源 ControlDesigner)
GetEmptyDesignTimeHtml()

取得 HTML 標記,以表示設計時的網頁伺服器控制項,執行時不會有視覺化表示。

(繼承來源 ControlDesigner)
GetErrorDesignTimeHtml(Exception)

取得提供指定例外資訊的 HTML 標記。

(繼承來源 ControlDesigner)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetPersistenceContent()

在設計時擷取控制項的持久性內部 HTML 標記。

(繼承來源 ControlDesigner)
GetPersistInnerHtml()
已淘汰.

取得控制項的持久性內部 HTML 標記。

(繼承來源 ControlDesigner)
GetService(Type)

嘗試從設計者元件的設計模式網站擷取指定類型的服務。

(繼承來源 ComponentDesigner)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
GetViewRendering()

擷取包含相關控制項內容及區域設計時標記的物件。

(繼承來源 ControlDesigner)
Initialize(IComponent)

將設計者綁定於控制項,並驗證該控制項是否為控制 WebPart 項。

InitializeExistingComponent(IDictionary)

重新初始化現有元件。

(繼承來源 ComponentDesigner)
InitializeNewComponent(IDictionary)

初始化新建立的元件。

(繼承來源 ComponentDesigner)
InitializeNonDefault()
已淘汰.
已淘汰.

初始化已初始化為非預設設定的匯入元件的設定。

(繼承來源 ComponentDesigner)
Invalidate()

會使設計表面上顯示的整個控制區域失效,並指示控制設計師重新繪製控制控制。

(繼承來源 ControlDesigner)
Invalidate(Rectangle)

使顯示在設計表面上的控制區域失效,並指示控制設計師重新繪製控制控制。

(繼承來源 ControlDesigner)
InvokeGetInheritanceAttribute(ComponentDesigner)

得到 InheritanceAttribute 指定的 ComponentDesigner。

(繼承來源 ComponentDesigner)
IsPropertyBound(String)
已淘汰.

擷取一個值,指示相關控制項上的指定屬性是否為資料綁定。

(繼承來源 ControlDesigner)
Localize(IDesignTimeResourceWriter)

利用提供的資源寫入器,將相關控制項的可區域化屬性持久化至設計主機中的資源。

(繼承來源 ControlDesigner)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
OnAutoFormatApplied(DesignerAutoFormat)

當已對相關控制項套用預先定義的自動格式化方案時,會呼叫此系統。

(繼承來源 ControlDesigner)
OnBehaviorDetaching()
已淘汰.

當行為與元素分離時被召喚。

(繼承來源 HtmlControlDesigner)
OnBindingsCollectionChanged(String)
已淘汰.

當資料綁定集合變更時會被呼叫。

(繼承來源 ControlDesigner)
OnClick(DesignerRegionMouseEventArgs)

當使用者在設計時點擊相關控制項時,設計主機會呼叫此功能。

(繼承來源 ControlDesigner)
OnComponentChanged(Object, ComponentChangedEventArgs)

當相關控制變更時會被呼叫。

(繼承來源 ControlDesigner)
OnComponentChanging(Object, ComponentChangingEventArgs)

代表將 ComponentChanging 處理相關控制項事件的方法。

(繼承來源 ControlDesigner)
OnControlResize()
已淘汰.

當設計主機在設計時調整了相關的網頁伺服器控制項時,會呼叫。

(繼承來源 ControlDesigner)
OnPaint(PaintEventArgs)

當控制設計者在設計表面繪製相關控制項時,若值 CustomPaint 為 true,則呼叫 。

(繼承來源 ControlDesigner)
OnSetComponentDefaults()
已淘汰.
已淘汰.

設定元件的預設屬性。

(繼承來源 ComponentDesigner)
OnSetParent()

提供一種當相關控制連接父控制時,執行額外處理的方式。

(繼承來源 HtmlControlDesigner)
PostFilterAttributes(IDictionary)

允許設計者更改或移除其透過 TypeDescriptor.

(繼承來源 ComponentDesigner)
PostFilterEvents(IDictionary)

允許設計者更改或移除透過 TypeDescriptor.

(繼承來源 ComponentDesigner)
PostFilterProperties(IDictionary)

允許設計者更改或移除透過 TypeDescriptor.

(繼承來源 ComponentDesigner)
PreFilterAttributes(IDictionary)

允許設計者透過 . 來擴充其所暴露 TypeDescriptor的屬性集合。

(繼承來源 ComponentDesigner)
PreFilterEvents(IDictionary)

設定元件物件在設計時 TypeDescriptor 會被暴露的事件清單。

(繼承來源 HtmlControlDesigner)
PreFilterProperties(IDictionary)

在設計時新增或移除設計主機的屬性網格中的屬性,或提供可能對應於相關控制項屬性的新設計時屬性。

(繼承來源 ControlDesigner)
RaiseComponentChanged(MemberDescriptor, Object, Object)

通知該 IComponentChangeService 元件已被更改。

(繼承來源 ComponentDesigner)
RaiseComponentChanging(MemberDescriptor)

通知該 IComponentChangeService 元件即將被更改。

(繼承來源 ComponentDesigner)
RaiseResizeEvent()
已淘汰.

引發 OnControlResize() 事件。

(繼承來源 ControlDesigner)
RegisterClone(Object, Object)

將內部資料登錄在克隆控制中。

(繼承來源 ControlDesigner)
SetEditableDesignerRegionContent(EditableDesignerRegion, String)

指定設計時控制項可編輯區域的內容。

(繼承來源 ControlDesigner)
SetRegionContent(EditableDesignerRegion, String)

在控制項設計時視圖中指定可編輯區域的內容。

(繼承來源 ControlDesigner)
SetViewFlags(ViewFlags, Boolean)

將指定的位 ViewFlags 元列舉分配給指定的旗標值。

(繼承來源 ControlDesigner)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)
UpdateDesignTimeHtml()

透過呼叫 GetDesignTimeHtml 該方法,刷新相關網頁伺服器控制項的設計時 HTML 標記。

(繼承來源 ControlDesigner)

明確介面實作

名稱 Description
IDesignerFilter.PostFilterAttributes(IDictionary)

關於此成員的描述,請參見方法。PostFilterAttributes(IDictionary)

(繼承來源 ComponentDesigner)
IDesignerFilter.PostFilterEvents(IDictionary)

關於此成員的描述,請參見方法。PostFilterEvents(IDictionary)

(繼承來源 ComponentDesigner)
IDesignerFilter.PostFilterProperties(IDictionary)

關於此成員的描述,請參見方法。PostFilterProperties(IDictionary)

(繼承來源 ComponentDesigner)
IDesignerFilter.PreFilterAttributes(IDictionary)

關於此成員的描述,請參見方法。PreFilterAttributes(IDictionary)

(繼承來源 ComponentDesigner)
IDesignerFilter.PreFilterEvents(IDictionary)

關於此成員的描述,請參見方法。PreFilterEvents(IDictionary)

(繼承來源 ComponentDesigner)
IDesignerFilter.PreFilterProperties(IDictionary)

關於此成員的描述,請參見方法。PreFilterProperties(IDictionary)

(繼承來源 ComponentDesigner)
ITreeDesigner.Children

關於此成員的描述,請參見 Children 該物業。

(繼承來源 ComponentDesigner)
ITreeDesigner.Parent

關於此成員的描述,請參見 Parent 該物業。

(繼承來源 ComponentDesigner)

適用於

另請參閱