Control クラスとは? わかりやすく解説

Control クラス

すべての ASP.NET サーバー コントロール共有するプロパティメソッド、およびイベント定義します

名前空間: System.Web.UI
アセンブリ: 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
/** @attribute BindableAttribute(true) */ 
/** @attribute ThemeableAttribute(false) */ 
public class Control implements IComponent,
 IDisposable, 
    IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor,
 IControlDesignerAccessor, 
    IExpressionsAccessor
BindableAttribute(true) 
ThemeableAttribute(false) 
public class Control implements 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>");
           }
       }
    }    
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
  System.Web.UI.Control
     派生クラス
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Control クラス

ビジュアルな表示コンポーネントであるコントロール基本クラス定義します

名前空間: System.Windows.Forms
アセンブリ: 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
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Control extends Component implements
 IDropTarget, ISynchronizeInvoke, 
    IWin32Window, IBindableComponent, IComponent, IDisposable
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class Control extends
 Component implements IDropTarget, ISynchronizeInvoke, 
    IWin32Window, IBindableComponent, IComponent, IDisposable
解説解説

独自のコントロール クラス作成するには、UserControl クラスControl クラス、または提供されその他の Windows フォーム コントロールか継承しますカスタム コントロール作成方法詳細については、「.NET Framework使用したカスタム Windows フォーム コントロール開発」を参照してください

Control クラスは、ユーザー情報表示するクラスが必要とする基本的な機能実装ます。ユーザー入力は、キーボードポインティング デバイスとおして処理されます。また、メッセージルーティングセキュリティ処理されます。コントロール範囲 (サイズ位置) は定義されますが、描画実装されません。ウィンドウハンドル (hWnd) も用意されます。

Windows フォーム コントロールアンビエント プロパティ使用するため、子コントロール周囲の環境のように表示できますアンビエント プロパティは、コントロール プロパティです。設定しない場合は、親コントロールか取得されます。コントロールParent がなく、プロパティ設定されていない場合コントロールSite プロパティとおしてアンビエント プロパティの値を決定しようとしますコントロール配置されていない場合、そのサイトアンビエント プロパティサポートしてない場合、または AmbientProperties にプロパティ設定されていない場合コントロールは独自の既定値使用します一般的にアンビエント プロパティは、子コントロール伝えられる BackColor などのコントロール特性表します。たとえば、Button は、既定では親の Form と同じ BackColor持ちますControl クラス提供されるアンビエント プロパティには、CursorFontBackColor、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.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
      System.Windows.Forms.Control
         派生クラス
スレッド セーフスレッド セーフ

スレッド セーフであるメンバは、BeginInvoke、EndInvoke、Invoke、InvokeRequired、および CreateGraphics だけです。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Control クラス」の関連用語

Control クラスのお隣キーワード
検索ランキング

   

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



Control クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS