Control クラス
アセンブリ: System.Web (system.web.dll 内)

<BindableAttribute(True)> _ <ThemeableAttribute(False)> _ Public Class Control Implements IComponent, IDisposable, IParserAccessor, IUrlResolutionService, _ IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
[BindableAttribute(true)] [ThemeableAttribute(false)] public class Control : IComponent, IDisposable, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
[BindableAttribute(true)] [ThemeableAttribute(false)] public ref class Control : IComponent, IDisposable, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor

これは、カスタム ASP.NET サーバー コントロールを開発するときに派生元となる主要なクラスです。Control にはユーザー インターフェイス (UI) に固有の機能はありません。UI を持たないコントロール、または独自の UI を表示するコントロールを組み合わせたコントロールを作成している場合は、Control から派生します。UI を持つコントロールを作成する場合は、System.Web.UI.WebControls 名前空間の WebControl またはその他のコントロールから派生します。これらのコントロールは、カスタム コントロール作成の適切な開始点として使用できます。
Control クラスは、カスタム コントロール、ユーザー コントロール、およびページなど、すべての ASP.NET サーバー コントロールの基本クラスです。ASP.NET ページは、Control クラスから継承する Page クラスのインスタンスであり、拡張子 .aspx を持つファイルに対する要求を処理します。
Control クラスは、Web アプリケーションのユーザー インターフェイスの一部として直接的または間接的に使用できます。このため、このクラスを使用する際は、安全なコードの作成およびアプリケーションのセキュリティ保護のためのベスト プラクティスに従っていることを注意深く確認する必要があります。これらのトピックの概要については、「Web アプリケーションのセキュリティ上の脅威の概要」、「セキュリティ ポリシーの実施」、および「セキュリティの基本概念」を参照してください。詳細については、「標準コントロールのセキュリティ保護」「方法 : 安全なエラー メッセージを表示する」、「方法 : HTML エンコーディングを文字列に適用して Web アプリケーションをスクリプトによる攻略から保護する」、および「検証コントロールの概要」を参照してください。

Control クラスから派生したカスタム サーバー コントロールの例を次に示します。InnerContent クラスは Control.Render メソッドをオーバーライドし、ページ上にクラスの子コントロールがあるかどうかを確認し、コントロールの最初の子がリテラル コントロールかどうかを調べます。これらの条件がいずれも満たされた場合、オーバーライドされたメソッドは HTML 文字列 (<H2>メッセージ : , リテラル コントロールの内容, および終了タグの </H2>) を Web フォーム ページに書き込みます。
Option Explicit Option Strict Imports System Imports System.Web Imports System.Web.UI Imports Microsoft.VisualBasic Namespace SimpleControlSamples Public Class InnerContent Inherits Control <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="Execution")> _ Protected Overrides Sub Render(output As HtmlTextWriter) If HasControls() And TypeOf Controls(0) Is LiteralControl Then output.Write("<H2>Your message : ") Controls(0).RenderControl(output) output.Write("</H2>") End If End Sub 'Render End Class 'InnerContent End Namespace 'SimpleControlSamples
using System; using System.Web; using System.Web.UI; namespace SimpleControlSamples { public class InnerContent : Control { [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="Execution")] protected override void Render(HtmlTextWriter output) { if ( (HasControls()) && (Controls[0] is LiteralControl) ) { output.Write("<H2>Your message : "); Controls[0].RenderControl(output); output.Write("</H2>"); } } } }
package SimpleControlSamples; import System.*; import System.Web.*; import System.Web.UI.*; public class InnerContent extends Control { /** @attribute System.Security.Permissions.PermissionSet( System.Security.Permissions.SecurityAction.Demand, Name = "Execution") */ protected void Render(HtmlTextWriter output) { if (HasControls() && get_Controls().get_Item(0) instanceof LiteralControl) { output.Write("<H2>Your message: "); get_Controls().get_Item(0).RenderControl(output); output.Write("</H2>"); } } //Render } //InnerContent
import System; import System.Web; import System.Web.UI; import System.Security.Permissions; package SimpleControlSamples { public class InnerContent extends Control { protected override function Render(output : HtmlTextWriter) { var securityperm : SecurityPermission; securityperm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter); securityperm.Demand(); if ( (HasControls()) && (typeof(Controls[0]) == LiteralControl) ) { output.Write("<H2>Your Message: " + (LiteralControl(Controls[0])).Text + "</H2>"); } } } }




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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Control クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ <ComVisibleAttribute(True)> _ Public Class Control Inherits Component Implements IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, _ IComponent, IDisposable
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] [ComVisibleAttribute(true)] public class Control : Component, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] [ComVisibleAttribute(true)] public ref class Control : public Component, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable

独自のコントロール クラスを作成するには、UserControl クラス、Control クラス、または提供されたその他の Windows フォーム コントロールから継承します。カスタム コントロールの作成方法の詳細については、「.NET Framework を使用したカスタム Windows フォーム コントロールの開発」を参照してください。
Control クラスは、ユーザーに情報を表示するクラスが必要とする基本的な機能を実装します。ユーザー入力は、キーボードとポインティング デバイスをとおして処理されます。また、メッセージのルーティングとセキュリティも処理されます。コントロールの範囲 (サイズと位置) は定義されますが、描画は実装されません。ウィンドウのハンドル (hWnd) も用意されます。
Windows フォーム コントロールはアンビエント プロパティを使用するため、子コントロールを周囲の環境のように表示できます。アンビエント プロパティは、コントロール プロパティです。設定しない場合は、親コントロールから取得されます。コントロールに Parent がなく、プロパティが設定されていない場合、コントロールは Site プロパティをとおしてアンビエント プロパティの値を決定しようとします。コントロールが配置されていない場合、そのサイトがアンビエント プロパティをサポートしていない場合、または AmbientProperties にプロパティが設定されていない場合、コントロールは独自の既定値を使用します。一般的に、アンビエント プロパティは、子コントロールに伝えられる BackColor などのコントロールの特性を表します。たとえば、Button は、既定では親の Form と同じ BackColor を持ちます。Control クラスで提供されるアンビエント プロパティには、Cursor、Font、BackColor、ForeColor、および RightToLeftがあります。
![]() |
---|
Windows フォーム アプリケーションを Windows XP visual スタイルをサポートするように設定するには、必ず FlatStyle プロパティを System に設定して、実行可能ファイルにマニフェストを含めます。マニフェストは、アプリケーション実行可能ファイルの中のリソースとして、または実行可能ファイルと同じディレクトリに存在する別個のファイルとして含まれる XML ファイルです。マニフェストの例については、FlatStyle 列挙体のトピックで「例」を参照してください。Windows XP で使用できる visual スタイルの使用方法の詳細については、MSDN ライブラリ (http://msdn.microsoft.com/library) の「Using Windows XP Visual Styles」を参照してください。 |
Windows フォームには、ユーザー補助のサポートが組み込まれており、ユーザー補助クライアント アプリケーションと協調して動作するための、アプリケーションに関する情報が提供されます。ユーザー補助クライアント アプリケーションには、画面拡大ユーティリティとレビューア ユーティリティ、音声入力ユーティリティ、オンスクリーン キーボード、代替入力デバイス、キーボード拡張ユーティリティなどがあります。こうしたユーザー補助クライアント アプリケーションに対して、追加情報を提供する必要が生じる場合があります。この追加情報を提供するには 2 つの方法があります。1 つは、ユーザー補助クライアント アプリケーションに報告される AccessibleName、AccessibleDescription、AccessibleDefaultActionDescription、AccessibleRole の各プロパティ値を設定する方法です。この方法は、一般に、既存のコントロール用の限定されたユーザー補助情報を提供するために使用されます。もう 1 つの方法として、AccessibleObject クラスまたは Control.ControlAccessibleObject クラスから派生させて独自のクラスを作成し、必要なユーザー補助情報をすべて提供することもできます。
System.Windows.Forms 名前空間にあるコントロールの多くは、基になる Windows コモン コントロールをベースとしてその上に構築されています。Windows コモン コントロールの詳細については、MSDN ライブラリ (http://msdn.microsoft.com/library) の「General Control Reference」を参照してください。
個別のプロセスから Windows フォーム コントロールを識別するには、標準の SendMessage 呼び出しを使用して WM_GETCONTROLNAME メッセージを渡します。WM_GETCONTROLNAME は、言語および Windows 階層には依存しません。詳細については、MSDN ライブラリ (http://msdn.microsoft.com/library) で「Automating Windows Forms」の「Recommended Solution for Windows Forms」を参照してください。

System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
派生クラス


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Control クラスのページへのリンク