LoginDesigner 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在視覺化設計工具中,為 Login Web 伺服器控制項提供設計階段支援。
public ref class LoginDesigner : System::Web::UI::Design::WebControls::CompositeControlDesigner
public class LoginDesigner : System.Web.UI.Design.WebControls.CompositeControlDesigner
type LoginDesigner = class
inherit CompositeControlDesigner
Public Class LoginDesigner
Inherits CompositeControlDesigner
- 繼承
範例
下列程式代碼範例示範如何擴充 LoginDesigner 類別,以變更在設計時間衍生自 Login 控件的控件外觀。
此範例會 MyLogin
從 Login衍生控件。
MyLogin
是控件的Login複本。 此範例也會從衍生 MyLoginDesigner
類別,並在控件上MyLogin
套用 DesignerAttribute 的屬性MyLoginDesigner
。LoginDesigner
會 MyLoginDesigner
覆寫 PreFilterProperties 方法,使 NamingContainer 屬性在設計時間顯示在 [屬性 ] 方格中。 如果控件的 MyLogin
屬性是 NotSet 或 None 值,它會覆寫 GetDesignTimeHtml 方法,以繪製控件周圍的藍色虛線框線,BorderStyle使其範圍更可見。 它會覆寫 GetErrorDesignTimeHtml 方法,以產生佔位符的標記,其中包含以紅色、粗體文字呈現的錯誤訊息。
using System;
using System.Web;
using System.Drawing;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;
namespace Examples.CS.WebControls.Design
{
// The MyLogin is a copy of the Login.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
[Designer(typeof(Examples.CS.WebControls.Design.MyLoginDesigner))]
public class MyLogin : Login
{
} // MyLogin
// Override members of the LoginDesigner.
[ReflectionPermission(SecurityAction.Demand, Flags=ReflectionPermissionFlag.MemberAccess)]
public class MyLoginDesigner : LoginDesigner
{
// Generate the design-time markup for the control when an error occurs.
protected override string GetErrorDesignTimeHtml(Exception e)
{
// Write the error message text in red, bold.
string errorRendering =
"<span style=\"font-weight:bold; color:Red; \">" +
e.Message + "</span>";
return CreatePlaceHolderDesignTimeHtml(errorRendering);
} // GetErrorDesignTimeHtml
// Shadow the control properties with design-time properties.
protected override void PreFilterProperties(IDictionary properties)
{
// Call the base method first.
base.PreFilterProperties(properties);
// Make the NamingContainer visible in the Properties grid.
PropertyDescriptor selectProp =
(PropertyDescriptor)properties["NamingContainer"];
properties["NamingContainer"] =
TypeDescriptor.CreateProperty(selectProp.ComponentType,
selectProp, BrowsableAttribute.Yes);
} // PreFilterProperties
// Generate the design-time markup.
public override string GetDesignTimeHtml()
{
// Make the control more visible in the designer. If the border
// style is None or NotSet, change the border to a blue dashed line.
MyLogin myLoginCtl = (MyLogin)ViewControl;
string markup = null;
// Check if the border style should be changed.
if (myLoginCtl.BorderStyle == BorderStyle.NotSet ||
myLoginCtl.BorderStyle == BorderStyle.None)
{
BorderStyle oldBorderStyle = myLoginCtl.BorderStyle;
Color oldBorderColor = myLoginCtl.BorderColor;
// Set the design time properties and catch any exceptions.
try
{
myLoginCtl.BorderStyle = BorderStyle.Dashed;
myLoginCtl.BorderColor = Color.Blue;
// Call the base method to generate the markup.
markup = base.GetDesignTimeHtml();
}
catch (Exception ex)
{
markup = GetErrorDesignTimeHtml(ex);
}
finally
{
// It is not necessary to restore the border properties
// to their original values because the ViewControl
// was used to reference the associated control and the
// UsePreviewControl was not overridden.
// myLoginCtl.BorderStyle = oldBorderStyle;
// myLoginCtl.BorderColor = oldBorderColor;
}
}
else
{
// Call the base method to generate the markup.
markup = base.GetDesignTimeHtml();
}
return markup;
} // GetDesignTimeHtml
} // MyLoginDesigner
} // Examples.CS.WebControls.Design
Imports System.Web
Imports System.Drawing
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports System.Collections
Imports System.ComponentModel
Imports System.Security.Permissions
Namespace Examples.VB.WebControls.Design
' The MyLogin is a copy of the Login.
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<Designer(GetType(Examples.VB.WebControls.Design.MyLoginDesigner))> _
Public Class MyLogin
Inherits Login
End Class
' Override members of the LoginDesigner.
<ReflectionPermission(SecurityAction.Demand, Flags:=ReflectionPermissionFlag.MemberAccess)> _
Public Class MyLoginDesigner
Inherits LoginDesigner
' Generate the design-time markup for the control when an error occurs.
Protected Overrides Function GetErrorDesignTimeHtml( _
ByVal ex As Exception) As String
' Write the error message text in red, bold.
Dim errorRendering As String = _
"<span style=""font-weight:bold; color:Red; "">" & _
ex.Message & "</span>"
Return CreatePlaceHolderDesignTimeHtml(errorRendering)
End Function ' GetErrorDesignTimeHtml
' Shadow the control properties with design-time properties.
Protected Overrides Sub PreFilterProperties( _
ByVal properties As IDictionary)
' Call the base method first.
MyBase.PreFilterProperties(properties)
' Make the NamingContainer visible in the Properties grid.
Dim selectProp As PropertyDescriptor = _
CType(properties("NamingContainer"), PropertyDescriptor)
properties("NamingContainer") = _
TypeDescriptor.CreateProperty(selectProp.ComponentType, _
selectProp, BrowsableAttribute.Yes)
End Sub
' Generate the design-time markup.
Public Overrides Function GetDesignTimeHtml() As String
' Make the control more visible in the designer. If the border
' style is None or NotSet, change the border to a blue dashed line.
Dim myLoginCtl As MyLogin = CType(ViewControl, MyLogin)
Dim markup As String = Nothing
' Check if the border style should be changed.
If (myLoginCtl.BorderStyle = BorderStyle.NotSet Or _
myLoginCtl.BorderStyle = BorderStyle.None) Then
Dim oldBorderStyle As BorderStyle = myLoginCtl.BorderStyle
Dim oldBorderColor As Color = myLoginCtl.BorderColor
' Set the design time properties and catch any exceptions.
Try
myLoginCtl.BorderStyle = BorderStyle.Dashed
myLoginCtl.BorderColor = Color.Blue
' Call the base method to generate the markup.
markup = MyBase.GetDesignTimeHtml()
Catch ex As Exception
markup = GetErrorDesignTimeHtml(ex)
Finally
' It is not necessary to restore the border properties
' to their original values because the ViewControl
' was used to reference the associated control and the
' UsePreviewControl was not overridden.
' myLoginCtl.BorderStyle = oldBorderStyle
' myLoginCtl.BorderColor = oldBorderColor
End Try
Else
' Call the base method to generate the markup.
markup = MyBase.GetDesignTimeHtml()
End If
Return markup
End Function ' GetDesignTimeHtml
End Class
End Namespace ' Examples.VB.WebControls.Design
備註
控制件 Login 會顯示允許使用者登入主網站的使用者介面。
在可視化設計工具中,當您從 [來源] 切換至 [設計] 檢視時,會剖析描述 Login 控件的標記原始程式碼,並在設計介面上建立控件的設計時間版本。 當您切換回 [來源] 檢視時,設計時間控件會保存到標記原始程式碼,並編輯成網頁的標記。 類別 LoginDesigner 提供控制件的設計時間支援 Login 。
類別 LoginDesigner 屬性提供下列功能:
屬性 ActionLists 會傳 DesignerActionListCollection 回 物件,該物件通常包含衍生自 DesignerActionList 設計工具繼承樹狀結構中每個層級之類別的物件。
屬性 AutoFormats 會傳回格式配置集合,以顯示在 [ 自動格式 ] 對話框中。
屬性 TemplateGroups 會傳回相關聯 Login 控件欄位和最上層 Login 範本的範本群組集合。
屬性 UsePreviewControl 一律會傳
true
回 ,表示設計工具會建立關聯的 Login 暫存複本,以產生設計時間標記。
類別 LoginDesigner 方法提供下列功能:
方法 GetDesignTimeHtml 會傳回標記,用來在設計時間呈現相關聯的 Login 。
方法 GetEditableDesignerRegionContent 會傳回相關聯 Login之範本的串行化複本。
方法 GetErrorDesignTimeHtml 會提供標記,用來在發生錯誤時呈現與設計時間相關聯的 Login 。
方法 Initialize 會準備設計工具,以檢視、編輯及設計相關聯的 Login。
方法 PreFilterProperties 可用來從中移除屬性、將其他屬性加入相關聯 Login之的陰影屬性或陰影屬性。
方法 SetEditableDesignerRegionContent 會從控件範本的串行化複本設定相關聯的 Login 區域。
建構函式
LoginDesigner() |
初始化 LoginDesigner 類別的新執行個體。 |
屬性
ActionLists |
取得此設計工具的設計工具動作清單集合。 |
AllowResize |
取得或設定值,這個值指定是否允許 LoginDesigner 控制項調整大小。 |
AllowResize |
取得值,指出是否可在設計階段環境中調整控制項的大小。 (繼承來源 ControlDesigner) |
AssociatedComponents |
取得元件集合,該集合與設計工具管理的元件相關聯。 (繼承來源 ComponentDesigner) |
AutoFormats |
取得要在 [自動格式化] 對話方塊中顯示之預先定義的格式化配置集合。 |
Behavior |
已淘汰.
取得或設定與設計工具相關聯的 DHTML 行為。 (繼承來源 HtmlControlDesigner) |
Component |
取得這個設計工具正在設計的元件。 (繼承來源 ComponentDesigner) |
DataBindings |
取得目前控制項的資料繫結 (Data Binding) 集合。 (繼承來源 HtmlControlDesigner) |
DataBindingsEnabled |
取得值,指出關聯控制項的包含區域是否支援資料繫結。 (繼承來源 ControlDesigner) |
DesignerState |
取得物件,用於在設計階段保存關聯控制項的資料。 (繼承來源 ControlDesigner) |
DesignTimeElement |
已淘汰.
取得設計階段物件,表示與設計介面上 HtmlControlDesigner 物件相關聯的控制項。 (繼承來源 HtmlControlDesigner) |
DesignTimeElementView |
已淘汰.
取得控制項設計工具的檢視控制項物件。 (繼承來源 ControlDesigner) |
DesignTimeHtmlRequiresLoadComplete |
已淘汰.
取得值,指出設計主應用程式在呼叫 GetDesignTimeHtml 方法之前是否必須完成載入。 (繼承來源 ControlDesigner) |
Expressions |
在設計階段取得目前控制項的運算式繫結。 (繼承來源 HtmlControlDesigner) |
HidePropertiesInTemplateMode |
取得值,指示當控制項處於樣板模式時,關聯控制項的屬性是否會隱藏。 (繼承來源 ControlDesigner) |
ID |
取得或設定控制項的 ID 字串。 (繼承來源 ControlDesigner) |
InheritanceAttribute |
取得屬性 (Attribute),表示相關元件的繼承 (Inheritance) 型別。 (繼承來源 ComponentDesigner) |
Inherited |
取得值,表示是否要繼承這個元件。 (繼承來源 ComponentDesigner) |
InTemplateMode |
取得值,指出控制項在設計主應用程式中處於樣板檢視模式還是編輯模式。 InTemplateMode 屬性是唯讀的。 (繼承來源 ControlDesigner) |
IsDirty |
已淘汰.
取得或設定值,指出 Web 伺服器控制項是否已標記為變更。 (繼承來源 ControlDesigner) |
ParentComponent |
取得這個設計工具的父元件。 (繼承來源 ComponentDesigner) |
ReadOnly |
已淘汰.
取得或設定值,指出控制項屬性於設計階段是否為唯讀。 (繼承來源 ControlDesigner) |
RenderOuterTable |
取得或設定值,這個值指定 LoginDesigner 控制項是否使用外部資料表容器來套用內嵌 CSS 樣式規則。 |
RootDesigner |
為包含關聯控制項的 Web Form 網頁,取得控制項設計工具。 (繼承來源 ControlDesigner) |
SetTextualDefaultProperty |
在視覺化設計工具中,為 Login Web 伺服器控制項提供設計階段支援。 (繼承來源 ComponentDesigner) |
ShadowProperties |
取得覆寫使用者設定的屬性值集合。 (繼承來源 ComponentDesigner) |
ShouldCodeSerialize |
已淘汰.
取得或設定值,指出是否應該於序列化 (Serialization) 期間,在程式碼後置 (Code-Behind) 檔案中為目前設計文件建立控制項的欄位宣告。 (繼承來源 HtmlControlDesigner) |
Tag |
取得物件,表示關聯控制項的 HTML 標記項目。 (繼承來源 ControlDesigner) |
TemplateGroups |
取得關聯控制項欄位的範本群組集合。 |
UsePreviewControl |
取得值,表示這個設計工具是否應該使用暫存複本來產生設計階段標記,而不是使用與設計工具關聯的實際控制項。 |
Verbs |
取得與設計工具相關元件所支援的設計階段動詞命令 (Verb)。 (繼承來源 ComponentDesigner) |
ViewControl |
取得或設定 Web 伺服器控制項,可用於預覽設計階段的 HTML 標記。 (繼承來源 ControlDesigner) |
ViewControlCreated |
取得或設定值,指出是否已建立 |
Visible |
取得值,這個值表示控制項在設計階段是否為可見的。 (繼承來源 ControlDesigner) |
方法
明確介面實作
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) |