この記事は翻訳者によって翻訳されたものです。 記事の文章にポインターを重ねると、原文のテキストが表示されます。
訳文
原文
このトピックはまだ評価されていません - このトピックを評価する

Control.FindForm メソッド

コントロールがあるフォームを取得します。

名前空間:  System.Windows.Forms
アセンブリ:  System.Windows.Forms (System.Windows.Forms.dll 内)
[UIPermissionAttribute(SecurityAction.Demand, Window = UIPermissionWindow.AllWindows)]
public Form FindForm()

戻り値

型: System.Windows.Forms.Form
コントロールがある Form

コントロールの Parent プロパティ値は、FindForm メソッドによって返された Form と同じではない場合があります。 たとえば、RadioButton コントロールが GroupBox コントロール内に格納されていて、GroupBoxForm 上にある場合、RadioButton コントロールの ParentGroupBox で、GroupBox コントロールの ParentForm です。

指定したボタンを含んだフォームを検索するコード例を次に示します。


// This example uses the Parent property and the Find method of Control to set
// properties on the parent control of a Button and its Form. The example assumes
// that a Button control named button1 is located within a GroupBox control. The 
// example also assumes that the Click event of the Button control is connected to
// the event handler method defined in the example.
private void button1_Click(object sender, System.EventArgs e)
{
   // Get the control the Button control is located in. In this case a GroupBox.
   Control control = button1.Parent;
   // Set the text and backcolor of the parent control.
   control.Text = "My Groupbox";
   control.BackColor = Color.Blue;
   // Get the form that the Button control is contained within.
   Form myForm = button1.FindForm();
   // Set the text and color of the form containing the Button.
   myForm.Text = "The Form of My Control";
   myForm.BackColor = Color.Red;
}


.NET Framework

サポート対象: 4、3.5、3.0、2.0、1.1、1.0

.NET Framework Client Profile

サポート対象: 4、3.5 SP1
  • UIPermission  

    (すべてのウィンドウでこのメソッドを呼び出すために必要なアクセス許可)。 UIPermissionWindowAllWindows 値 (関連する列挙体)

Windows 7, Windows Vista SP1 以降, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core はサポート対象外), Windows Server 2008 R2 (SP1 以降で Server Core をサポート), Windows Server 2003 SP2

.NET Framework では、各プラットフォームのすべてのバージョンはサポートしていません。 サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
この情報は役に立ちましたか。
(残り 1500 文字)
コミュニティ コンテンツ 追加
注釈 FAQ