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

Form クラス

コントロールグループ化する機能提供します

名前空間: System.Web.UI.MobileControls
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)
構文構文

Public Class Form
    Inherits Panel
    Implements ITemplateable, IPostBackEventHandler
public class Form : Panel, ITemplateable, IPostBackEventHandler
public ref class Form : public
 Panel, ITemplateable, IPostBackEventHandler
public class Form extends Panel implements
 ITemplateable, IPostBackEventHandler
public class Form extends
 Panel implements ITemplateable, IPostBackEventHandler
解説解説

フォームは、ASP.NET モバイル Web ページ内で最も外側コントロール グループ表現します個々モバイル Web ページには、最も外側レベル複数フォーム格納できますフォーム入れ子にすることはできません。コンテナ入れ子にしたい場合は、Panel コントロール使用してください詳細については、「Form コントロール概要」を参照してください特定のフォーム表示するには、現在のページ上で ActiveForm プロパティ目的フォーム設定するか、Link コントロールの NavigateUrl プロパティ目的フォーム設定しますForm コントロールテキストには、マークアップ タグを伴うリテラル テキスト含めることができますテンプレート使用する場合は、Form コントロールフォームの OnInit メソッドテンプレートインスタンス作成することに注意してくださいフォームOnInit メソッドは、Page_Load および Page_Init より前に呼び出されます。また、この時点ではフォームがまだ作成されていないため、ページ コンストラクタでは実行タイミングが早すぎて OnInit メソッドテンプレート設定することはできません。この問題修正するには、フォーム自体OnInit メソッドフックし、そこでテンプレートインスタンス作成します詳細については、「テンプレート レンダリング実装」を参照してください

使用例使用例

2 つフォームがあり、そのフォーム間にリンクがあるページ作成する方法次のコード例示します一方フォームにはチェック ボックス リストあります。項目を選択して [送信] ボタンクリックすると、選択した項目とその値の一覧がフォーム表示されます。Activate イベント メソッドは、各フォーム表示準備します

メモメモ

次のコード例はシングルファイル コード モデル使用しており、分離コード ファイル直接コピーされ場合正常に動作しない可能性あります。このコード例は、拡張子.aspx の空のテキスト ファイルコピーする必要があります詳細については、「ASP.NET Web ページコード モデル」を参照してください

<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage"
 %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls"
 
    Assembly="System.Web.Mobile"
 %>
<%@ Import Namespace="System.Web.Mobile"
 %>
<%@ Import Namespace="System.Web.UI.MobileControls"
 %>
<%@ Import Namespace="System.Drawing"
 %>

<script runat="server">
    ' When Form1 is activated
    Private Sub Form1_Activate(ByVal
 sender As Object, _
        ByVal e As EventArgs)
        Dim viewText As String
 = "You have viewed this Form {0} times."
        
        ' First viewing
        If (count = 0) Then
            message2.Text = "Welcome to the Form Sample"
        Else ' subsequent viewings
            message2.Text = String.Format(viewText, _
              (count + 1).ToString())
        End If
        
        ' Format the form
        Form1.Alignment = Alignment.Center
        Form1.Wrapping = Wrapping.NoWrap
        Form1.BackColor = Color.LightBlue
        Form1.ForeColor = Color.Blue
        Form1.Paginate = True

        ' Create an array and add the tasks to it.
        Dim arr As ArrayList = New
 ArrayList()
        arr.Add(New Task("Verify transactions",
 "Done"))
        arr.Add(New Task("Check balance sheet",
 "Scheduled"))
        arr.Add(New Task("Send report",
 "Pending"))

        ' Bind the SelectionList to the array.
        SelectionList1.DataValueField = "Status"
        SelectionList1.DataTextField = "TaskName"
        SelectionList1.DataSource = arr
        SelectionList1.DataBind()
    End Sub

    ' When Form1 is deactivated
    Private Sub Form1_Deactivate(ByVal
 sender As Object, _
        ByVal e As EventArgs)

        count += 1
    End Sub

    ' When Form2 is activated
    Private Sub Form2_Activate(ByVal
 sender As Object, _
        ByVal e As EventArgs)
    
        Form2.BackColor = Color.DarkGray
        Form2.ForeColor = Color.White
        Form2.Font.Bold = BooleanOption.True
    End Sub

    ' The the Submit button is clicked
    Protected Sub Command1_OnSubmit(ByVal
 sender As Object, _
        ByVal e As EventArgs)

        Dim i As Integer
        message2.Text = "FORM RESULTS:"
        message2.Font.Bold = BooleanOption.True

        ' Create a string and a TextView control
        Dim txtView As TextView = New
 TextView()
        Dim txt As String
 = ""
        Dim spec As String
 = "{0} is {1}<br />"
        
        ' Display a list of selected items with values
        For i = 0 To SelectionList1.Items.Count
 - 1
            ' Get the ListItem
            Dim itm As MobileListItem = SelectionList1.Items(i)
            
            ' List the selected items and values
            If itm.Selected Then
                txt &= String.Format(spec, itm.Text, itm.Value)
            End If
        Next
        
        ' Put the text into the TextView
        txtView.Text = txt
        ' Add the TextView to the form
        Form1.Controls.Add(txtView)
        
        ' Hide unnecessary controls
        SelectionList1.Visible = False
        link1.Visible = False
        Command1.Visible = False
    End Sub

    ' Property to persist the count between postbacks
    Private Property count() As
 Integer
        Get
            Dim o As Object
 = ViewState("FormCount")
            If IsNothing(o) Then
                Return 0
            Else
                Return CType(o, Integer)
            End If
        End Get
        Set(ByVal value As
 Integer)
            ViewState("FormCount") = value
        End Set
    End Property

    ' A custom class for the task array
    Private Class Task
        Private _TaskName As String
        Private _Status As String

        Public Sub New(ByVal
 TaskName As String, ByVal
 Status As String)
            _TaskName = TaskName
            _Status = Status
        End Sub

        Public ReadOnly Property
 TaskName() As String
            Get
                Return _TaskName
            End Get
        End Property
        Public ReadOnly Property
 Status() As String
            Get
                Return _Status
            End Get
        End Property
    End Class

</script>

<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
    <!-- The first form: Form1 -->
    <mobile:Form ID="Form1" Runat="server"
        OnDeactivate="Form1_Deactivate" 
        OnActivate="Form1_Activate">
        <mobile:Label ID="message1" Runat="server">
            Welcome to ASP.NET
        </mobile:Label>
        
        <mobile:Label ID="message2" Runat="server"
 />
        <mobile:SelectionList Runat="server" 
            ID="SelectionList1" 
            ForeColor="red" SelectType="CheckBox"
 />
        <mobile:Link ID="link1" Runat="server"
 
            NavigateUrl="#Form2" 
            Text="Next Form" /><br />
        <mobile:Command ID="Command1" Runat="server"
 
            Text="Submit" OnClick="Command1_OnSubmit"
 />
    </mobile:Form>

    <!-- The second form: Form2 -->
    <mobile:Form ID="Form2" Runat="server"
 
        OnActivate="Form2_Activate">
        <mobile:Label ID="message4" Runat="server">
           Welcome to ASP.NET
        </mobile:Label> 
        <mobile:Link ID="Link2" Runat="server"
 
            NavigateUrl="#Form1" Text="Back"
 />
    </mobile:Form>
</body>
</html>
<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.UI.MobileControls" %>
<%@ Import Namespace="System.Drawing" %>

<script runat="server">
    // When Form1 is activated
    private void Form1_Activate(object sender,
 EventArgs e)
    {
        string viewText = "You have viewed this
 Form {0} times.";
        
        if (count == 0) // First viewing
            message2.Text = "Welcome to the Form Sample";
        else // subsequent viewings
            message2.Text = String.Format(viewText,
              (count + 1).ToString());
        
        // Format the form
        Form1.Alignment = Alignment.Center;
        Form1.Wrapping = Wrapping.NoWrap;
        Form1.BackColor = Color.LightBlue;
        Form1.ForeColor = Color.Blue;
        Form1.Paginate = true;

        // Create an array and add the tasks to it.
        ArrayList arr = new ArrayList();
        arr.Add(new Task("Verify transactions", "Done"));
        arr.Add(new Task("Check balance sheet", "Scheduled"));
        arr.Add(new Task("Send report", "Pending"));

        // Bind the SelectionList to the array.
        SelectionList1.DataValueField = "Status";
        SelectionList1.DataTextField = "TaskName";
        SelectionList1.DataSource = arr;
        SelectionList1.DataBind();
    }

    // When Form1 is deactivated
    private void Form1_Deactivate(object sender,
 EventArgs e)
    {
        count++;
    }

    // When Form2 is activated
    private void Form2_Activate(object sender,
 EventArgs e)
    {
        Form2.BackColor = Color.DarkGray;
        Form2.ForeColor = Color.White;
        Form2.Font.Bold = BooleanOption.True;
    }

    // The the Submit button is clicked
    protected void Command1_OnSubmit(object
 sender, EventArgs e)
    {
        message2.Text = "FORM RESULTS:";
        message2.Font.Bold = BooleanOption.True;

        // Display a list of selected items with values
        for (int i = 0; i < SelectionList1.Items.Count;
 i++)
        {
            // Create a string and a TextView control
            TextView txtView = new TextView();
            string txt = "";
            string spec = "{0} is {1}<br />";

            // Display a list of selected items with values
            // Get the list item
            MobileListItem itm = SelectionList1.Items[i];

            // List the selected items and values
            if (itm.Selected)
            {
                txt += String.Format(spec, itm.Text, itm.Value);
            }
            
            // Put the text into the TextView
            txtView.Text = txt;
            // Add txtView to the form
            Form1.Controls.Add(txtView);
        }
        
        // Hide unnecessary controls
        SelectionList1.Visible = false;
        link1.Visible = false;
        Command1.Visible = false;
    }

    // Property to persist the count between postbacks
    private int count
    {
        get
        {
            object o = ViewState["FormCount"];
            return o == null ? 0 : (int)o;
        }
        set { ViewState["FormCount"] = value; }
    }


    // A custom class for the task array
    private class Task
    {
        private String _TaskName;
        private String _Status;

        public Task(String TaskName, String Status)
        {
            _TaskName = TaskName;
            _Status = Status;
        }

        public String TaskName
        {
            get { return _TaskName; }
        }
        public String Status
        {
            get { return _Status; }
        }
    }
</script>

<html  >
<body>
    <!-- The first form: Form1 -->
    <mobile:Form ID="Form1" Runat="server"
        OnDeactivate="Form1_Deactivate" 
        OnActivate="Form1_Activate">
        <mobile:Label ID="message1" Runat="server">
            Welcome to ASP.NET
        </mobile:Label>
        
        <mobile:Label ID="message2" Runat="server" />
        <mobile:SelectionList Runat="server" 
            ID="SelectionList1" 
            ForeColor="red" SelectType="CheckBox" />
        <mobile:Link ID="link1" Runat="server" 
            NavigateUrl="#Form2" 
            Text="Next Form" /><br />
        <mobile:Command ID="Command1" Runat="server" 
            Text="Submit" OnClick="Command1_OnSubmit" />
    </mobile:Form>

    <!-- The second form: Form2 -->
    <mobile:Form ID="Form2" Runat="server" 
        OnActivate="Form2_Activate">
        <mobile:Label ID="message4" Runat="server">
           Welcome to ASP.NET
        </mobile:Label> 
        <mobile:Link ID="Link2" Runat="server" 
            NavigateUrl="#Form1" Text="Back" />
    </mobile:Form>
</body>
</html>
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.MobileControls.MobileControl
       System.Web.UI.MobileControls.Panel
        System.Web.UI.MobileControls.Form
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Form クラス

アプリケーションユーザー インターフェイス構成するウィンドウまたはダイアログ ボックス表します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class Form
    Inherits ContainerControl
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class Form : ContainerControl
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class Form : public
 ContainerControl
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class Form extends ContainerControl
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class Form extends
 ContainerControl
解説解説

Form は、アプリケーション表示されるあらゆるウィンドウ表しますForm クラス使用すると、ツール格納する標準的な境界線のないフローティング ウィンドウ作成できます。また Form クラスは、ダイアログ ボックスなどのモーダル ウィンドウ作成する目的でも使用できます特殊なフォームであるマルチ ドキュメント インターフェイス (MDI: Multiple Document Interface) フォームには、MDIフォーム呼ばれる別のフォーム格納できますMDI フォームは、IsMdiContainer プロパティtrue設定することによって作成しますMDIフォームは、MdiParent プロパティに、その子フォーム格納する MDIフォーム設定することによって作成します

Form クラス用意されているプロパティ使用すると、作成するウィンドウダイアログ ボックス外観サイズ、色、およびウィンドウ管理機能決定できますText プロパティでは、タイトル バー表示されるウィンドウキャプション指定できますSize プロパティと DesktopLocation プロパティでは、ウィンドウ表示されたときのサイズ位置を定義できます。ForeColor 色プロパティ使用すると、フォーム上に配置されるすべてのコントロール既定前景色を変更できます。FormBorderStyle、MinimizeBox、および MaximizeBox の各プロパティでは、実行時フォーム最小化最大化、またはサイズ変更許可するかどうか制御できます

プロパティの他に、このクラスメソッド使用してフォーム操作することもできます。たとえば、ShowDialog メソッド使用すると、フォームモーダル ダイアログ ボックスとして表示できます。また SetDesktopLocation メソッド使用すると、デスクトップ上のフォーム位置設定できます

Form クラスイベント使用すると、フォーム対して実行されるアクション応答できますActivated イベント使用すると、フォームアクティブになったときに、フォームコントロール内に表示されるデータ更新するなどの操作実行できます

このクラスMain呼ばれるメソッド配置することにより、フォームアプリケーション起動時クラスとして使用できます。この Main メソッド内に、フォーム作成して表示するコード追加しますフォーム実行するには、Main メソッドSTAThread 属性追加する必要があります起動フォーム閉じられると、アプリケーション閉じられます。

使用例使用例

Form新しインスタンス作成しShowDialog メソッド呼び出してフォームダイアログ ボックスとして表示するコード例次に示します。この例では、FormBorderStyle、AcceptButton、CancelButton、MinimizeBoxMaximizeBox、StartPosition の各プロパティ設定してフォーム外観と機能変更しダイアログ ボックスとして表示します。この例では、フォームControls コレクションAdd メソッド使用して2 つButton コントロール追加しますまた、HelpButton プロパティ使用してダイアログ ボックスキャプション バーヘルプ ボタン表示します

Public Sub CreateMyForm()
    ' Create a new instance of the form.
    Dim form1 As New Form()
    ' Create two buttons to use as the accept and cancel buttons.
    Dim button1 As New Button()
    Dim button2 As New Button()
       
    ' Set the text of button1 to "OK".
    button1.Text = "OK"
    ' Set the position of the button on the form.
    button1.Location = New Point(10, 10)
    ' Set the text of button2 to "Cancel".
    button2.Text = "Cancel"
    ' Set the position of the button based on the location of button1.
    button2.Location = _
       New Point(button1.Left, button1.Height + button1.Top +
 10)
    ' Set the caption bar text of the form.   
    form1.Text = "My Dialog Box"
    ' Display a help button on the form.
    form1.HelpButton = True
       
    ' Define the border style of the form to a dialog box.
    form1.FormBorderStyle = FormBorderStyle.FixedDialog
    ' Set the MaximizeBox to false to remove the maximize box.
    form1.MaximizeBox = False
    ' Set the MinimizeBox to false to remove the minimize box.
    form1.MinimizeBox = False
    ' Set the accept button of the form to button1.
    form1.AcceptButton = button1
    ' Set the cancel button of the form to button2.
    form1.CancelButton = button2
    ' Set the start position of the form to the center of the screen.
    form1.StartPosition = FormStartPosition.CenterScreen
       
    ' Add button1 to the form.
    form1.Controls.Add(button1)
    ' Add button2 to the form.
    form1.Controls.Add(button2)
       
    ' Display the form as a modal dialog box.
    form1.ShowDialog()
End Sub
public void CreateMyForm()
{
   // Create a new instance of the form.
   Form form1 = new Form();
   // Create two buttons to use as the accept and cancel buttons.
   Button button1 = new Button ();
   Button button2 = new Button ();
  
   // Set the text of button1 to "OK".
   button1.Text = "OK";
   // Set the position of the button on the form.
   button1.Location = new Point (10, 10);
   // Set the text of button2 to "Cancel".
   button2.Text = "Cancel";
   // Set the position of the button based on the location of button1.
   button2.Location
      = new Point (button1.Left, button1.Height + button1.Top
 + 10);
   // Set the caption bar text of the form.   
   form1.Text = "My Dialog Box";
   // Display a help button on the form.
   form1.HelpButton = true;

   // Define the border style of the form to a dialog box.
   form1.FormBorderStyle = FormBorderStyle.FixedDialog;
   // Set the MaximizeBox to false to remove the maximize box.
   form1.MaximizeBox = false;
   // Set the MinimizeBox to false to remove the minimize box.
   form1.MinimizeBox = false;
   // Set the accept button of the form to button1.
   form1.AcceptButton = button1;
   // Set the cancel button of the form to button2.
   form1.CancelButton = button2;
   // Set the start position of the form to the center of the screen.
   form1.StartPosition = FormStartPosition.CenterScreen;
   
   // Add button1 to the form.
   form1.Controls.Add(button1);
   // Add button2 to the form.
   form1.Controls.Add(button2);
   
   // Display the form as a modal dialog box.
   form1.ShowDialog();
}
public:
   void CreateMyForm()
   {
      // Create a new instance of the form.
      Form^ form1 = gcnew Form;
      // Create two buttons to use as the accept and cancel buttons.
      Button^ button1 = gcnew Button;
      Button^ button2 = gcnew Button;
      
      // Set the text of button1 to "OK".
      button1->Text = "OK";
      // Set the position of the button on the form.
      button1->Location = Point(10,10);
      // Set the text of button2 to "Cancel".
      button2->Text = "Cancel";
      // Set the position of the button based on the location of button1.
      button2->Location =
         Point( button1->Left, button1->Height + button1->Top + 10 );
      // Set the caption bar text of the form.   
      form1->Text = "My Dialog Box";
      // Display a help button on the form.
      form1->HelpButton = true;
      
      // Define the border style of the form to a dialog box.
      form1->FormBorderStyle = ::FormBorderStyle::FixedDialog;
      // Set the MaximizeBox to false to remove the maximize box.
      form1->MaximizeBox = false;      
      // Set the MinimizeBox to false to remove the minimize box.
      form1->MinimizeBox = false;
      // Set the accept button of the form to button1.
      form1->AcceptButton = button1;
      // Set the cancel button of the form to button2.
      form1->CancelButton = button2;
      // Set the start position of the form to the center of the screen.
      form1->StartPosition = FormStartPosition::CenterScreen;
      
      // Add button1 to the form.
      form1->Controls->Add( button1 );
      // Add button2 to the form.
      form1->Controls->Add( button2 );
      // Display the form as a modal dialog box.
      form1->ShowDialog();
   }
public void CreateMyForm()
{
    // Create a new instance of the form.
    Form form1 = new Form();

    // Create two buttons to use as the accept and cancel buttons.
    Button button1 = new Button();
    Button button2 = new Button();

    // Set the text of button1 to "OK".
    button1.set_Text("OK");

    // Set the position of the button on the form.
    button1.set_Location(new Point(10, 10));

    // Set the text of button2 to "Cancel".
    button2.set_Text("Cancel");

    // Set the position of the button based on the location of button1.
    button2.set_Location(new Point(button1.get_Left(), 
        button1.get_Height() + button1.get_Top() + 10));

    // Set the caption bar text of the form.   
    form1.set_Text("My Dialog Box");

    // Display a help button on the form.
    form1.set_HelpButton(true);

    // Define the border style of the form to a dialog box.
    form1.set_FormBorderStyle(get_FormBorderStyle().FixedDialog);

    // Set the MaximizeBox to false to remove the maximize box.
    form1.set_MaximizeBox(false);

    // Set the MinimizeBox to false to remove the minimize box.
    form1.set_MinimizeBox(false);

    // Set the accept button of the form to button1.
    form1.set_AcceptButton(button1);

    // Set the cancel button of the form to button2.
    form1.set_CancelButton(button2);

    // Set the start position of the form to the center of the screen.
    form1.set_StartPosition(FormStartPosition.CenterScreen);

    // Add button1 to the form.
    form1.get_Controls().Add(button1);

    // Add button2 to the form.
    form1.get_Controls().Add(button2);

    // Display the form as a modal dialog box.
    form1.ShowDialog();
} //CreateMyForm
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ContainerControl
            System.Windows.Forms.Form
               派生クラス
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「Form クラス」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS