ControlDesigner.ViewControl プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ControlDesigner.ViewControl プロパティの意味・解説 

ControlDesigner.ViewControl プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

デザイン時 HTML マークアップのプレビュー用に使用できる Web サーバー コントロールを取得または設定します。

名前空間: System.Web.UI.Design
アセンブリ: System.Design (system.design.dll 内)
構文構文

Dim instance As ControlDesigner
Dim value As Control

value = instance.ViewControl

instance.ViewControl = value
public Control ViewControl { get; set;
 }
/** @property */
public Control get_ViewControl ()

/** @property */
public void set_ViewControl (Control value)

プロパティ値
デザイン時 HTML マークアップを生成するために基本クラスが使用する Control。

解説解説

ViewControl プロパティは、UsePreviewControl プロパティを使用して戻り値を決定します。

UsePreviewControl プロパティが true の場合、ViewControl プロパティはコントロールの一時コピーを返します。一時コントロールに加えられた変更は永続化されません。

UsePreviewControl プロパティが false の場合、ViewControl プロパティはコントロールの Component プロパティのインスタンスを返します。コントロールのインスタンスに加えられた変更は永続化されます。

SupportsPreviewControlAttribute オブジェクト内の SupportsPreviewControl 設定は、UsePreviewControl プロパティの値を設定するために使用します。したがって、SupportsPreviewControl の設定により、基本 ControlDesigner クラスの ViewControl プロパティによって返されるコントロールの種類が決定されます。SupportsPreviewControlAttribute がコントロール デザイナの宣言内で指定されていない場合、ControlDesigner の動作は SupportsPreviewControl プロパティに false を設定した場合と同じになります。

使用例使用例

SupportsPreviewControlAttribute 属性を使用してコントロール デザイナをマークする方法を次のコード例に示します。このコード例は、Label クラスから Web サーバー コントロールを派生し、そのコントロールをカスタム コントロール デザイナ実装に関連付けます。コントロール デザイナ クラス宣言は、true に設定された SupportsPreviewControl 属性でマークされます。コントロール デザイナは、GetDesignTimeHtml メソッドをオーバーライドし、デザイン時にコントロールの Text プロパティを斜体で表示します。

Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.Design.WebControls
Imports System.Web.UI.WebControls
Imports System.Reflection

Namespace ControlDesignerSamples.VB

    ' Derive a simple Web control from Label to render a text string.
    ' Associate this control with the SimpleTextControlDesigner.
    <DesignerAttribute("ControlDesignerSamples.CS.SimpleTextControlDesigner"),
 _
    ToolboxData("<{0}:MyLabelControl Runat=""Server""><{0}:MyLabelControl>")>
 _
    Public Class MyLabelControl
        Inherits Label

        ' Use the Label control implementation, but associate
        ' the derived class with the custom control designer.
    End Class


    ' Mark the designer with the SupportsPreviewControlAttribute set
    ' to true.  This means the base.UsePreviewControl returns true,
    ' and base.ViewControl returns a temporary preview copy of the control.
    <SupportsPreviewControl(True)> _
    Public Class SimpleTextControlDesigner
        Inherits TextControlDesigner

        ' Override the base GetDesignTimeHtml method to display 
        ' the design time text in italics.
        Public Overrides Function
 GetDesignTimeHtml() As String
            Dim html As String
 = String.Empty

            Try
                ' Get the ViewControl for the associated control.
                Dim ctrl As Label = CType(ViewControl,
 Label)

                ' Set the default text, if necessary
                If ctrl.Text.Length = 0 Then
                    ctrl.Text = "Sample Text"
                End If

                ' Set the style to italic
                ctrl.Style.Add(HtmlTextWriterStyle.FontStyle, "italic")

                ' Let the base class create the HTML markup
                html = MyBase.GetDesignTimeHtml()
            Catch ex As Exception
                If String.IsNullOrEmpty(html)
 Then
                    ' Display the exception message
                    html = GetErrorDesignTimeHtml(ex)
                End If
            End Try

            Return html
        End Function

    End Class
End Namespace
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
using System.Web.UI.WebControls;
using System.Reflection;

namespace ControlDesignerSamples.CS
{
    // Define a simple designer associated with a 
    // simple text web control.
    
    // Mark the designer with the SupportsPreviewControlAttribute set
    // to true.  This means the base.UsePreviewControl returns true
,
    // and base.ViewControl returns a temporary preview copy of the
 control.
    [SupportsPreviewControl(true)]
    public class SimpleTextControlDesigner
 : TextControlDesigner
    {        
        // Override the base GetDesignTimeHtml method to display 
        // the design time text in italics.
        public override string GetDesignTimeHtml()
        {
            string html = String.Empty;
 
            try
            {
                // Initialize the return string to the default
                // design time html of the base TextControlDesigner.
                html = base.GetDesignTimeHtml();

                // Get the ViewControl for the associated control.
                Label ctrl = (Label)ViewControl;

                ctrl.Style.Add(HtmlTextWriterStyle.FontStyle, "Italic");
                html = base.GetDesignTimeHtml();

            }
            catch (System.Exception e)
            {
               if (String.IsNullOrEmpty(html))
               {
                   html = GetErrorDesignTimeHtml(e);
               }
            }
            
            return html;
        }

    }

    // Derive a simple Web control from Label to render a text string.
    // Associate this control with the SimpleTextControlDesigner.
    [DesignerAttribute("ControlDesignerSamples.CS.SimpleTextControlDesigner")
,
    ToolboxData("<{0}:MyLabelControl Runat=\"Server\"><{0}:MyLabelControl>")]
    public class MyLabelControl : Label
    {
        // Use the Label control implementation, but associate
        // the derived class with the custom control designer.
    }
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ControlDesigner クラス
ControlDesigner メンバ
System.Web.UI.Design 名前空間
SupportsPreviewControlAttribute
ControlDesigner.UsePreviewControl プロパティ
GetViewRendering
SupportsPreviewControlAttribute
PreviewControlDesigner
その他の技術情報
ASP.NET コントロール デザイナの概要
Web フォームのデザイン時サポート



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ControlDesigner.ViewControl プロパティ」の関連用語

ControlDesigner.ViewControl プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ControlDesigner.ViewControl プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS