ControlDesigner.UpdateDesignTimeHtml メソッド
コントロールの表示を更新します。
Public Overridable Sub UpdateDesignTimeHtml()
[C#]
public virtual void UpdateDesignTimeHtml();
[C++]
public: virtual void UpdateDesignTimeHtml();
[JScript]
public function UpdateDesignTimeHtml();
解説
このメソッドは、コントロールが変更された場合などに、コントロールの表示を更新するために呼び出されます。デザイナは、コントロールの値を変更した後にこのメソッドを呼び出して、コントロールの表示を更新する必要があります。
メモ ComponentChanged イベントを呼び出すと、 IComponentChangeService インターフェイスが UpdateDesignTimeHtml メソッドを呼び出します。
使用例
[Visual Basic, C#, C++] カスタムの toggleTextSize メソッドの例を次に示します。この toggleTextSize は、呼び出されると IsDirty プロパティを true に設定し、 UpdateDesignTimeHtml メソッドを呼び出します。
Imports System
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports Microsoft.VisualBasic
Namespace Examples.AspNet
' This control designer offers designer verb menu commands
' that can alter the design time html provided for the
' System.Web.UI.Control this designer supports.
Public Class TextSizeWebControlDesigner
Inherits System.Web.UI.Design.ControlDesigner
' Whether to display the html of the associated
' control using a large heading text size.
Private LargeText As Boolean
Private dvc As DesignerVerbCollection = Nothing
Public Sub New()
LargeText = True
End Sub
' Provides a menu command to toggle the text size.
Public Overrides ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection
Get
Dim verbReduce As DesignerVerb = _
New DesignerVerb("Reduce text size", New EventHandler(AddressOf Me.toggleTextSize))
Dim verbEnlarge As DesignerVerb = _
New DesignerVerb("Enlarge text size", New EventHandler(AddressOf Me.toggleTextSize))
If dvc Is Nothing Then
dvc = New DesignerVerbCollection()
dvc.Add(verbReduce)
dvc.Add(verbEnlarge)
ElseIf (dvc.Contains(verbEnlarge) = False) Then
dvc.Add(verbEnlarge)
ElseIf (dvc.Contains(verbReduce) = False) Then
dvc.Add(verbReduce)
End If
If LargeText Then
dvc.Remove(verbEnlarge)
Else
dvc.Remove(verbReduce)
End If
Return dvc
End Get
End Property
' Returns the html to use to represent the control at design time.
Public Overrides Function GetDesignTimeHtml() As String
Dim html As String = MyBase.GetDesignTimeHtml()
If LargeText Then
Return "<H1>" + html + "</H1>"
Else
Return "<H3>" + html + "</H3>"
End If
End Function
' Event handler to toggle whether the html receives a large or
' small size heading markup tag.
Private Sub ToggleTextSize(ByVal sender As Object, ByVal e As EventArgs)
If LargeText Then
LargeText = False
Else
LargeText = True
End If
Me.IsDirty = True
Me.UpdateDesignTimeHtml()
End Sub
End Class
' Simple text Web control renders a text string.
' This control is associated with the TextSizeWebControlDesigner.
<DesignerAttribute(GetType(TextSizeWebControlDesigner), GetType(IDesigner))> _
Public Class TextControl
Inherits System.Web.UI.WebControls.WebControl
Private [text_] As String
<Bindable(True), Category("Appearance"), DefaultValue("")> _
Public Property [Text]() As String
Get
Dim o As Object = ViewState("Text")
Return IIf(o Is Nothing, String.Empty, CStr(o))
End Get
Set
If HasControls() Then
Controls.Clear()
End If
ViewState("Text") = value
End Set
End Property
Public Sub New()
[text_] = "Test phrase"
End Sub
Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)
output.Write([Text])
End Sub
End Class
[C#]
using System;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;
namespace Examples.AspNet
{
// This control designer offers designer verb menu commands
// that can alter the design time html provided for the
// System.Web.UI.Control this designer supports.
public class TextSizeWebControlDesigner : System.Web.UI.Design.ControlDesigner
{
// Whether to display the html of the associated
// control using a large heading text size.
private bool LargeText;
private DesignerVerbCollection dvc;
public TextSizeWebControlDesigner() : base()
{
LargeText = true;
}
// Provides a menu command to toggle the text size.
public override System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
DesignerVerb verbReduce = new DesignerVerb("Reduce text size", new EventHandler(this.ToggleTextSize));
DesignerVerb verbEnlarge = new DesignerVerb("Enlarge text size", new EventHandler(this.ToggleTextSize));
if (dvc == null){
dvc = new DesignerVerbCollection();
dvc.Add(verbReduce);
dvc.Add(verbEnlarge);
}
else if (dvc.Contains(verbEnlarge) == false){
dvc.Add(verbEnlarge);
}
else if (dvc.Contains(verbReduce) == false){
dvc.Add(verbReduce);
}
if( LargeText )
dvc.Remove(verbEnlarge);
else
dvc.Remove(verbReduce);
return dvc;
}
}
// Returns the html to use to represent the control at design time.
public override string GetDesignTimeHtml()
{
string html = base.GetDesignTimeHtml();
if( LargeText )
return "<H1>"+html+"</H1>";
else
return "<H3>"+html+"</H3>";
}
// Event handler to toggle whether the html receives a large or
// small size heading markup tag.
private void ToggleTextSize(object sender, EventArgs e)
{
if( LargeText )
LargeText = false;
else
LargeText = true;
this.IsDirty = true;
this.UpdateDesignTimeHtml();
}
}
// Simple text Web control renders a text string.
// This control is associated with the TextSizeWebControlDesigner.
[DesignerAttribute(typeof(TextSizeWebControlDesigner), typeof(IDesigner))]
public class TextControl : System.Web.UI.WebControls.WebControl
{
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
object o = ViewState["Text"];
return((o == null) ? String.Empty : (string)o);
}
set
{
if (HasControls()) {
Controls.Clear();
}
ViewState["Text"] = value;
}
}
public TextControl()
{
Text = "Test phrase";
}
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(Text);
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.dll>
#using <System.Web.dll>
#using <System.Design.dll>
using namespace System;
using namespace System::Web::UI;
using namespace System::Web::UI::Design;
using namespace System::Web::UI::WebControls;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
// This control designer offers designer verb menu commands
// that can alter the design time html provided for the
// System::Web::UI::Control this designer supports.
public __gc class TextSizeWebControlDesigner : public ControlDesigner {
// Whether to display the html of the associated
// control using a large heading text size.
private:
bool LargeText;
public:
TextSizeWebControlDesigner() : ControlDesigner() {
LargeText = true;
}
// Provides a menu command to toggle the text size.
public:
__property System::ComponentModel::Design::DesignerVerbCollection* get_Verbs() {
DesignerVerbCollection* dvc = new DesignerVerbCollection();
if (LargeText)
dvc->Add(new DesignerVerb(S"Reduce text size",
new EventHandler(this, &TextSizeWebControlDesigner::ToggleTextSize)));
else
dvc->Add(new DesignerVerb(S"Enlarge text size",
new EventHandler(this, &TextSizeWebControlDesigner::ToggleTextSize)));
return dvc;
}
// Returns the html to use to represent the control at design time.
public:
String* GetDesignTimeHtml() {
String* html = __super::GetDesignTimeHtml();
if (LargeText)
return String::Concat(S"<H1> ", html, S"</H1>");
else
return String::Concat(S"<H3> ", html, S"</H3>");
}
// Event handler to toggle whether the html receives a large or
// small size heading markup tag.
private:
void ToggleTextSize(Object* /*sender*/, EventArgs* /*e*/) {
if (LargeText)
LargeText = false;
else
LargeText = true;
this->IsDirty = true;
this->UpdateDesignTimeHtml();
}
};
// Simple text Web control renders a text string.
// This control is associated with the TextSizeWebControlDesigner.
[DesignerAttribute(__typeof(TextSizeWebControlDesigner), __typeof(IDesigner))]
public __gc class TextControl : public WebControl {
private:
String* text;
public:
[Bindable(true),
Category(S"Appearance"),
DefaultValue(S"")]
__property String* get_Text() {
return text;
}
__property void set_Text(String* value) {
text = value;
}
TextControl() {
text = S"Test phrase";
}
protected:
void Render(HtmlTextWriter* output) {
output->Write(Text);
}
};
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
.NET Framework セキュリティ:
- 直前の呼び出し元の完全信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細の参照先 : 部分信頼コードからのライブラリの使用
参照
ControlDesigner クラス | ControlDesigner メンバ | System.Web.UI.Design 名前空間