HyperLinkDesigner クラス
アセンブリ: System.Design (system.design.dll 内)
構文
解説
HyperLink コントロールは、クライアントのブラウザで他の Web ページに移動するためのリンクを作成します。
ビジュアルなデザイナでソース ビューからデザイン ビューに切り替えると、HyperLink コントロールを記述するマークアップのソース コードが解析され、コントロールのデザイン時バージョンがデザイン サーフェイスに作成されます。元のソース ビューに切り替えると、デザイン時コントロールがマークアップのソース コードに永続化され、Web ページのマークアップに反映されます。HyperLinkDesigner クラスは、HyperLink コントロールをデザイン時に使用できるようにします。
GetDesignTimeHtml メソッドは、関連付けられた HyperLink コントロールのデザイン時表示に使用するマークアップを返します。OnComponentChanged メソッドは、関連付けられたコントロールに変更があった場合に呼び出されます。
このセクションには、2 つのコード例が含まれています。最初の例では、HyperLinkDesigner クラスからクラスを派生して、メソッドをオーバーライドし、プロパティ値を提供する方法を示します。2 番目の例では、HyperLink コントロールからコントロールを派生して、そのコントロールに属性を適用する方法を示します。
HyperLinkDesigner クラスから CustomHyperLinkDesigner クラスを派生する方法を次のコード例に示します。Text の元の値が空の文字列 ("") である場合、GetDesignTimeHtml メソッドをオーバーライドして Text プロパティの既定値を提供します。これにより、関連付けられたコントロールがデザイン時に表示されるようになります。
' Derive the CustomHyperLinkDesigner from the HyperLinkDesigner. Public Class CustomHyperLinkDesigner Inherits HyperLinkDesigner ' Override the GetDesignTimeHtml to set the CustomHyperLink Text ' property so that it displays at design time. Public Overrides Function GetDesignTimeHtml() As String Dim hype As CustomHyperLink = CType(Component, CustomHyperLink) Dim designTimeMarkup As String = Nothing ' Save the original Text and note if it is empty. Dim text As String = hype.Text Dim noText As Boolean = (text.Trim().Length = 0) Try ' If the Text is empty, supply a default value. If noText Then hype.Text = "Click here." End If ' Call the base method to generate the markup. designTimeMarkup = MyBase.GetDesignTimeHtml() Catch ex As Exception ' If an error occurs, generate the markup for an error message. designTimeMarkup = GetErrorDesignTimeHtml(ex) Finally ' Restore the original value of the Text, if necessary. If noText Then hype.Text = text End If End Try ' If the markup is empty, generate the markup for a placeholder. If ((designTimeMarkup = Nothing) Or _ (designTimeMarkup.Length = 0)) Then designTimeMarkup = GetEmptyDesignTimeHtml() End If Return designTimeMarkup End Function ' GetDesignTimeHtml End Class ' CustomHyperLinkDesigner
// Derive the CustomHyperLinkDesigner from the HyperLinkDesigner. public class CustomHyperLinkDesigner : HyperLinkDesigner { // Override the GetDesignTimeHtml to set the CustomHyperLink Text // property so that it displays at design time. public override string GetDesignTimeHtml() { CustomHyperLink hype = (CustomHyperLink)Component; string designTimeMarkup = null; // Save the original Text and note if it is empty. string text = hype.Text; bool noText = (text.Trim().Length == 0); try { // If the Text is empty, supply a default value. if (noText) hype.Text = "Click here."; // Call the base method to generate the markup. designTimeMarkup = base.GetDesignTimeHtml(); } catch (Exception ex) { // If an error occurs, generate the markup for an error message. designTimeMarkup = GetErrorDesignTimeHtml(ex); } finally { // Restore the original value of the Text, if necessary. if (noText) hype.Text = text; } // If the markup is empty, generate the markup for a placeholder. if(designTimeMarkup == null || designTimeMarkup.Length == 0) designTimeMarkup = GetEmptyDesignTimeHtml(); return designTimeMarkup; } // GetDesignTimeHtml } // CustomHyperLinkDesigner
HyperLink コントロールから CustomHyperLink コントロールを派生して、DesignerAttribute 属性を CustomHyperLink コントロールに適用して CustomHyperLinkDesigner と関連付ける方法を次のコード例に示します。
Imports System.Web Imports System.ComponentModel Imports System.Web.UI.WebControls Imports System.Security.Permissions Namespace Examples.VB.WebControls.Design ' The CustomHyperLink is a copy of the HyperLink. ' It uses the CustomHyperLinkDesigner for design-time support. <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermission(SecurityAction.InheritanceDemand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <Designer(GetType(Examples.VB.WebControls.Design. _ CustomHyperLinkDesigner))> _ Public Class CustomHyperLink Inherits HyperLink End Class ' CustomHyperLink End Namespace ' Examples.VB.WebControls.Design
using System.Web; using System.Web.UI.WebControls; using System.ComponentModel; using System.Security.Permissions; namespace Examples.CS.WebControls.Design { // The CustomHyperLink is a copy of the HyperLink. // It uses the CustomHyperLinkDesigner for design-time support. [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [Designer(typeof(Examples.CS.WebControls.Design. CustomHyperLinkDesigner))] public class CustomHyperLink : HyperLink { } // CustomHyperLink } // Examples.CS.WebControls.Design
- SecurityPermission (アンマネージ コードを呼び出すために必要なアクセス許可) 要求値 : Demand。アクセス許可値 : UnmanagedCode。
System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
System.Web.UI.Design.TextControlDesigner
System.Web.UI.Design.WebControls.HyperLinkDesigner
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- HyperLinkDesigner クラスのページへのリンク