ApplicationContextとは? わかりやすく解説

ApplicationContext イベント


パブリック イベントパブリック イベント

  名前 説明
パブリック イベント ThreadExit ExitThread を呼び出したことにより、スレッドメッセージ ループ終了したときに発生します
参照参照

関連項目

ApplicationContext クラス
System.Windows.Forms 名前空間

ApplicationContext クラス

アプリケーション スレッドに関するコンテキスト情報指定します

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

Public Class ApplicationContext
    Implements IDisposable
Dim instance As ApplicationContext
public class ApplicationContext : IDisposable
public ref class ApplicationContext : IDisposable
public class ApplicationContext implements
 IDisposable
public class ApplicationContext implements
 IDisposable
解説解説
使用例使用例

2 つフォーム表示し両方フォーム閉じられたときにアプリケーション終了するコード例を、次に示しますアプリケーション開始時と終了時に、各フォーム位置記憶されます。この例では、ApplicationContextApplication.Run(context) メソッドと共に使用してアプリケーション起動時複数フォーム表示する方法示します

MyApplicationContext クラスは、ApplicationContext継承クラスで、各フォームがいつ閉じられたのかを追跡し両方フォーム閉じられたときに現在のスレッド終了します。このクラスは、ユーザー代わりにフォーム位置格納しますフォーム位置データは、Appdata.txt という名前のファイル格納されます。このファイルは、UserAppDataPath で指定された場所に作成されます。

Main メソッドは、Application.Run(context)呼び出すことにより、ApplicationContext指定してアプリケーション起動します。

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Text
Imports System.IO

' A simple form that represents a window in our application
Public Class AppForm1
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        Me.Size = New System.Drawing.Size(300,
 300)
        Me.Text = "AppForm1"

    End Sub

End Class

' A simple form that represents a window in our application
Public Class AppForm2
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        Me.Size = New System.Drawing.Size(300,
 300)
        Me.Text = "AppForm2"

    End Sub

End Class

' The class that handles the creation of the application windows
Public Class MyApplicationContext
    Inherits ApplicationContext

    Private formCount As Integer
    Private form1 As AppForm1
    Private form2 As AppForm2

    Private form1Position As Rectangle
    Private form2Position As Rectangle

    Private userData As FileStream

    Public Sub New()
        MyBase.New()
        formCount = 0

        ' Handle the ApplicationExit event to know when the application
 is exiting.
        AddHandler Application.ApplicationExit, AddressOf
 OnApplicationExit

        Try
            ' Create a file that the application will store user specific
 data in.
            userData = New FileStream(Application.UserAppDataPath
 + "\appdata.txt", FileMode.OpenOrCreate)

        Catch e As IOException
            ' Inform the user that an error occurred.
            MessageBox.Show("An error occurred while attempting
 to show the application." + _
                            "The error is:" + e.ToString())

            ' Exit the current thread instead of showing the windows.
            ExitThread()
        End Try

        ' Create both application forms and handle the Closed event
        ' to know when both forms are closed.
        form1 = New AppForm1()
        AddHandler form1.Closed, AddressOf
 OnFormClosed
        AddHandler form1.Closing, AddressOf
 OnFormClosing
        formCount = formCount + 1

        form2 = New AppForm2()
        AddHandler form2.Closed, AddressOf
 OnFormClosed
        AddHandler form2.Closing, AddressOf
 OnFormClosing
        formCount = formCount + 1

        ' Get the form positions based upon the user specific data.
        If (ReadFormDataFromFile()) Then
            ' If the data was read from the file, set the form
            ' positions manually.
            form1.StartPosition = FormStartPosition.Manual
            form2.StartPosition = FormStartPosition.Manual

            form1.Bounds = form1Position
            form2.Bounds = form2Position
        End If

        ' Show both forms.
        form1.Show()
        form2.Show()
    End Sub

    Private Sub OnApplicationExit(ByVal
 sender As Object, ByVal
 e As EventArgs)
        ' When the application is exiting, write the application data
 to the
        ' user file and close it.
        WriteFormDataToFile()

        Try
            ' Ignore any errors that might occur while closing the file
 handle.
            userData.Close()
        Catch
        End Try
    End Sub

    Private Sub OnFormClosing(ByVal
 sender As Object, ByVal
 e As CancelEventArgs)
        ' When a form is closing, remember the form position so it
        ' can be saved in the user data file.
        If TypeOf sender Is
 AppForm1 Then
            form1Position = CType(sender, Form).Bounds
        ElseIf TypeOf sender Is
 AppForm2 Then
            form2Position = CType(sender, Form).Bounds
        End If
    End Sub
    
    Private Sub OnFormClosed(ByVal
 sender As Object, ByVal
 e As EventArgs)
        ' When a form is closed, decrement the count of open forms.

        ' When the count gets to 0, exit the app by calling
        ' ExitThread().
        formCount = formCount - 1
        If (formCount = 0) Then
            ExitThread()
        End If
    End Sub

    Private Function WriteFormDataToFile()
 As Boolean
        ' Write the form positions to the file.
        Dim encoding As UTF8Encoding = New
 UTF8Encoding()

        Dim rectConv As RectangleConverter
 = New RectangleConverter()
        Dim form1pos As String
 = rectConv.ConvertToString(form1Position)
        Dim form2pos As String
 = rectConv.ConvertToString(form2Position)

        Dim dataToWrite As Byte()
 = encoding.GetBytes("~" + form1pos + "~"
 + form2pos)

        Try
            ' Set the write position to the start of the file and write
            userData.Seek(0, SeekOrigin.Begin)
            userData.Write(dataToWrite, 0, dataToWrite.Length)
            userData.Flush()

            userData.SetLength(dataToWrite.Length)
            Return True

        Catch
            ' An error occurred while attempting to write, return false.
            Return False
        End Try

    End Function

    Private Function ReadFormDataFromFile()
 As Boolean
        ' Read the form positions from the file.
        Dim encoding As UTF8Encoding = New
 UTF8Encoding()
        Dim data As String

        If (userData.Length <> 0) Then
            Dim dataToRead(userData.Length) As
 Byte

            Try
                ' Set the read position to the start of the file and
 read.
                userData.Seek(0, SeekOrigin.Begin)
                userData.Read(dataToRead, 0, dataToRead.Length)

            Catch e As IOException
                Dim errorInfo As String
 = e.ToString()
                ' An error occurred while attempt to read, return false.
                Return False
            End Try

            ' Parse out the data to get the window rectangles
            data = encoding.GetString(dataToRead)

            Try
                ' Convert the string data to rectangles
                Dim rectConv As RectangleConverter
 = New RectangleConverter()
                Dim form1pos As String
 = data.Substring(1, data.IndexOf("~", 1) - 1)

                form1Position = CType(rectConv.ConvertFromString(form1pos), Rectangle)

                Dim form2pos As String
 = data.Substring(data.IndexOf("~", 1) + 1)
                form2Position = CType(rectConv.ConvertFromString(form2pos), Rectangle)

                Return True

            Catch
                ' Error occurred while attempting to convert the rectangle
 data.
                ' Return false to use default values.
                Return False
            End Try

        Else
            ' No data in the file, return false to use default values.
            Return False
        End If
    End Function

End Class

Public Module MyApplication
    Public Sub Main()
        ' Create the MyApplicationContext, that derives from ApplicationContext
,
        ' that manages when the application should exit.

        Dim context As MyApplicationContext
 = New MyApplicationContext()

        ' Run the application with the specific context. It will exit
 when
        ' all forms are closed.
        Application.Run(context)
    End Sub
End Module
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text;
using System.IO;

namespace MyApplication
{
    // A simple form that represents a window in our application
    public class AppForm2 : System.Windows.Forms.Form
 {
        public AppForm2(){ 
            this.Size = new System.Drawing.Size(300
,300);
            this.Text = "AppForm2";
        }
    }

    // A simple form that represents a window in our application
    public class AppForm1 : System.Windows.Forms.Form
 {
        public AppForm1(){ 
            this.Size = new System.Drawing.Size(300
,300);
            this.Text = "AppForm1";
        }
    }

    // The class that handles the creation of the application windows
    class MyApplicationContext : ApplicationContext {
    
        private int formCount;
        private AppForm1 form1;
        private AppForm2 form2;

        private Rectangle form1Position;
        private Rectangle form2Position;

        private FileStream userData;

        private MyApplicationContext() {
            formCount = 0;

            // Handle the ApplicationExit event to know when the application
 is exiting.
            Application.ApplicationExit += new EventHandler(this.OnApplicationExit);

            try {
                // Create a file that the application will store user
 specific data in.
                userData = new FileStream(Application.UserAppDataPath
 + "\\appdata.txt", FileMode.OpenOrCreate);

            } catch(IOException e) {
                // Inform the user that an error occurred.
                MessageBox.Show("An error occurred while
 attempting to show the application." + 
                                "The error is:" + e.ToString());

                // Exit the current thread instead of showing the windows.
                ExitThread();
            }

            // Create both application forms and handle the Closed event
            // to know when both forms are closed.
            form1 = new AppForm1();
            form1.Closed += new EventHandler(OnFormClosed);  
          
            form1.Closing += new CancelEventHandler(OnFormClosing);
            
            formCount++;

            form2 = new AppForm2();
            form2.Closed += new EventHandler(OnFormClosed);  
          
            form2.Closing += new CancelEventHandler(OnFormClosing);
            
            formCount++;

            // Get the form positions based upon the user specific data.
            if (ReadFormDataFromFile()) {
                // If the data was read from the file, set the form
                // positions manually.
                form1.StartPosition = FormStartPosition.Manual;
                form2.StartPosition = FormStartPosition.Manual;
                
                form1.Bounds = form1Position;
                form2.Bounds = form2Position;
            }

            // Show both forms.
            form1.Show();
            form2.Show();
        }

        private void OnApplicationExit(object
 sender, EventArgs e) {
            // When the application is exiting, write the application
 data to the
            // user file and close it.
            WriteFormDataToFile();

            try {
                // Ignore any errors that might occur while closing
 the file handle.
                userData.Close();
            } catch {}
        }

        private void OnFormClosing(object sender,
 CancelEventArgs e) {
            // When a form is closing, remember the form position so
 it
            // can be saved in the user data file.
            if (sender is AppForm1) 
                form1Position = ((Form)sender).Bounds;
            else if (sender is AppForm2)
                form2Position = ((Form)sender).Bounds;
        }

        private void OnFormClosed(object sender,
 EventArgs e) {
            // When a form is closed, decrement the count of open forms.

            // When the count gets to 0, exit the app by calling
            // ExitThread().
            formCount--;
            if (formCount == 0) {
                ExitThread();
            }
        }

        private bool WriteFormDataToFile(){
            // Write the form positions to the file.
            UTF8Encoding encoding = new UTF8Encoding();

            RectangleConverter rectConv = new RectangleConverter();
            String form1pos = rectConv.ConvertToString(form1Position);
            String form2pos = rectConv.ConvertToString(form2Position);

            byte[] dataToWrite = encoding.GetBytes("~" + form1pos + "~"
 + form2pos);

            try {
                // Set the write position to the start of the file and
 write
                userData.Seek(0,SeekOrigin.Begin);
                userData.Write(dataToWrite, 0, dataToWrite.Length);
                userData.Flush();

                userData.SetLength(dataToWrite.Length);
                return true;

            } catch {
                // An error occurred while attempting to write, return
 false.
                return false;
            }

        }

        private bool ReadFormDataFromFile(){
            // Read the form positions from the file.
            UTF8Encoding encoding = new UTF8Encoding();
            String data;

            if (userData.Length != 0) {
                byte[] dataToRead = new Byte[userData.Length];

                try {
                    // Set the read position to the start of the file
 and read.
                    userData.Seek(0, SeekOrigin.Begin);
                    userData.Read(dataToRead, 0, dataToRead.Length);

                } catch (IOException e) {
                    String errorInfo = e.ToString();
                    // An error occurred while attempt to read, return
 false.
                    return false;
                }

                // Parse out the data to get the window rectangles
                data = encoding.GetString(dataToRead);

                try {
                    // Convert the string data to rectangles
                    RectangleConverter rectConv = new RectangleConverter();
                    String form1pos = data.Substring(1,data.IndexOf("~"
,1)-1);

                    form1Position = (Rectangle)rectConv.ConvertFromString(form1pos);

                    String form2pos = data.Substring(data.IndexOf("~",1)+1);
                    form2Position = (Rectangle)rectConv.ConvertFromString(form2pos);

                    return true;

                } catch {
                    // Error occurred while attempting to convert the
 rectangle data.
                    // Return false to use default values.
                    return false;
                }

            } else {
                // No data in the file, return false to use default
 values.
                return false;
            }
        }        
        
        [STAThread]
        static void Main(string[]
 args) {
            
            // Create the MyApplicationContext, that derives from ApplicationContext
,
            // that manages when the application should exit.

            MyApplicationContext context = new MyApplicationContext();

            // Run the application with the specific context. It will
 exit when
            // all forms are closed.
            Application.Run(context);

        }
    }
}
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::ComponentModel;
using namespace System::Text;
using namespace System::IO;

// A simple form that represents a window in our application
public ref class AppForm2: public
 System::Windows::Forms::Form
{
public:
   AppForm2()
   {
      this->Size = System::Drawing::Size( 300, 300 );
      this->Text = "AppForm2";
   }

};


// A simple form that represents a window in our application
public ref class AppForm1: public
 System::Windows::Forms::Form
{
public:
   AppForm1()
   {
      this->Size = System::Drawing::Size( 300, 300 );
      this->Text = "AppForm1";
   }

};


// The class that handles the creation of the application windows
ref class MyApplicationContext: public ApplicationContext
{
private:
   int formCount;
   AppForm1^ form1;
   AppForm2^ form2;
   System::Drawing::Rectangle form1Position;
   System::Drawing::Rectangle form2Position;
   FileStream^ userData;

public:

   MyApplicationContext()
   {
      formCount = 0;
      
      // Handle the ApplicationExit event to know when the application
 is exiting.
      Application::ApplicationExit += gcnew EventHandler( this,
 &MyApplicationContext::OnApplicationExit );
      try
      {
         
         // Create a file that the application will store user specific
 data in.
         userData = gcnew FileStream( String::Concat( Application::UserAppDataPath,
 "\\appdata.txt" ),FileMode::OpenOrCreate );
      }
      catch ( IOException^ e ) 
      {
         
         // Inform the user that an error occurred.
         MessageBox::Show( "An error occurred while attempting
 to show the application. The error is: {0}", dynamic_cast<String^>(e)
 );
         
         // Exit the current thread instead of showing the windows.
         ExitThread();
      }

      
      // Create both application forms and handle the Closed event
      // to know when both forms are closed.
      form1 = gcnew AppForm1;
      form1->Closed += gcnew EventHandler( this, &MyApplicationContext::OnFormClosed
 );
      form1->Closing += gcnew CancelEventHandler( this, &MyApplicationContext::OnFormClosing
 );
      formCount++;
      form2 = gcnew AppForm2;
      form2->Closed += gcnew EventHandler( this, &MyApplicationContext::OnFormClosed
 );
      form2->Closing += gcnew CancelEventHandler( this, &MyApplicationContext::OnFormClosing
 );
      formCount++;
      
      // Get the form positions based upon the user specific data.
      if ( ReadFormDataFromFile() )
      {
         
         // If the data was read from the file, set the form
         // positions manually.
         form1->StartPosition = FormStartPosition::Manual;
         form2->StartPosition = FormStartPosition::Manual;
         form1->Bounds = form1Position;
         form2->Bounds = form2Position;
      }

      
      // Show both forms.
      form1->Show();
      form2->Show();
   }

   void OnApplicationExit( Object^ /*sender*/, EventArgs^ /*e*/
 )
   {
      
      // When the application is exiting, write the application data
 to the
      // user file and close it.
      WriteFormDataToFile();
      try
      {
         
         // Ignore any errors that might occur while closing the file
 handle.
         userData->Close();
      }
      catch ( Exception^ ) 
      {
      }

   }


private:

   void OnFormClosing( Object^ sender, CancelEventArgs^ /*e*/
 )
   {
      
      // When a form is closing, remember the form position so it
      // can be saved in the user data file.
      if ( dynamic_cast<AppForm1^>(sender) != nullptr )
            form1Position = (dynamic_cast<Form^>(sender))->Bounds;
      else
      if ( dynamic_cast<AppForm1^>(sender) != nullptr )
            form2Position = (dynamic_cast<Form^>(sender))->Bounds;
   }


   void OnFormClosed( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      
      // When a form is closed, decrement the count of open forms.
      // When the count gets to 0, exit the app by calling
      // ExitThread().
      formCount--;
      if ( formCount == 0 )
      {
         ExitThread();
      }
   }


   bool WriteFormDataToFile()
   {
      
      // Write the form positions to the file.
      UTF8Encoding^ encoding = gcnew UTF8Encoding;
      RectangleConverter^ rectConv = gcnew RectangleConverter;
      String^ form1pos = rectConv->ConvertToString( form1Position );
      String^ form2pos = rectConv->ConvertToString( form2Position );
      array<Byte>^dataToWrite = encoding->GetBytes( String::Concat( "~",
 form1pos, "~", form2pos ) );
      try
      {
         
         // Set the write position to the start of the file and write
         userData->Seek( 0, SeekOrigin::Begin );
         userData->Write( dataToWrite, 0, dataToWrite->Length );
         userData->Flush();
         userData->SetLength( dataToWrite->Length );
         return true;
      }
      catch ( Exception^ ) 
      {
         
         // An error occurred while attempting to write, return false.
         return false;
      }

   }

   bool ReadFormDataFromFile()
   {
      
      // Read the form positions from the file.
      UTF8Encoding^ encoding = gcnew UTF8Encoding;
      String^ data;
      if ( userData->Length != 0 )
      {
         array<Byte>^dataToRead = gcnew array<Byte>(userData->Length);
         try
         {
            
            // Set the read position to the start of the file and read.
            userData->Seek( 0, SeekOrigin::Begin );
            userData->Read( dataToRead, 0, dataToRead->Length );
         }
         catch ( IOException^ e ) 
         {
            String^ errorInfo = dynamic_cast<String^>(e);
            
            // An error occurred while attempt to read, return false.
            return false;
         }

         
         // Parse out the data to get the window rectangles
         data = encoding->GetString( dataToRead );
         try
         {
            
            // Convert the String* data to rectangles
            RectangleConverter^ rectConv = gcnew RectangleConverter;
            String^ form1pos = data->Substring( 1, data->IndexOf( "~",
 1 ) - 1 );
            form1Position =  *safe_cast<Rectangle^>(rectConv->ConvertFromString(
 form1pos ));
            String^ form2pos = data->Substring( data->IndexOf( "~",
 1 ) + 1 );
            form2Position =  *safe_cast<Rectangle^>(rectConv->ConvertFromString(
 form2pos ));
            return true;
         }
         catch ( Exception^ ) 
         {
            
            // Error occurred while attempting to convert the rectangle
 data.
            // Return false to use default values.
            return false;
         }

      }
      else
      {
         
         // No data in the file, return false to use default values.
         return false;
      }
   }

};



[STAThread]
int main()
{
   
   // Create the MyApplicationContext, that derives from ApplicationContext
,
   // that manages when the application should exit.
   MyApplicationContext^ context = gcnew MyApplicationContext;
   
   // Run the application with the specific context. It will exit when
   // all forms are closed.
   Application::Run( context );
}

package MyApplication; 

import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;
import System.ComponentModel.*;
import System.Text.*;
import System.IO.*;
   
// A simple form that represents a window in our application
public class AppForm2 extends System.Windows.Forms.Form
{
    public AppForm2()
    {
        this.set_Size(new System.Drawing.Size(300,
 300));
        this.set_Text("AppForm2");
    } //AppForm2
} //AppForm2
   
// A simple form that represents a window in our application
public class AppForm1 extends System.Windows.Forms.Form
{
    public AppForm1()
    {
        this.set_Size(new System.Drawing.Size(300,
 300));
        this.set_Text("AppForm1");
    } //AppForm1
} //AppForm1
   
// The class that handles the creation of the application windows
class MyApplicationContext extends ApplicationContext
{
    private int formCount;
    private AppForm1 form1;
    private AppForm2 form2;
    private Rectangle form1Position;
    private Rectangle form2Position;
    private FileStream userData;

    private MyApplicationContext()
    {
        formCount = 0;

        // Handle the ApplicationExit event to know 
        // when the application is exiting.
        Application.add_ApplicationExit(new EventHandler(
            this.OnApplicationExit));
        try {
            // Create a file that the application will store 
            // user specific data in.
            userData = new FileStream(Application.get_UserAppDataPath()
 
                + "\\appdata.txt", FileMode.OpenOrCreate);
        }
        catch (IOException e) {
            // Inform the user that an error occurred.
            MessageBox.Show("An error occurred while attempting
 to show the "
                + " application. The error is:" + e.ToString());

            // Exit the current thread instead of showing the windows.
            ExitThread();
        }

        // Create both application forms and handle the Closed event
        // to know when both forms are closed.
        form1 = new AppForm1();
        form1.add_Closed(new EventHandler(OnFormClosed));
        form1.add_Closing(new CancelEventHandler(OnFormClosing));
        formCount++;
        form2 = new AppForm2();
        form2.add_Closed(new EventHandler(OnFormClosed));
        form2.add_Closing(new CancelEventHandler(OnFormClosing));
        formCount++;

        // Get the form positions based upon the user specific data.
        if (ReadFormDataFromFile()) {
            // If the data was read from the file, set the form
            // positions manually.
            form1.set_StartPosition(FormStartPosition.Manual);
            form2.set_StartPosition(FormStartPosition.Manual);
            form1.set_Bounds(form1Position);
            form2.set_Bounds(form2Position);
        }

        // Show both forms.
        form1.Show();
        form2.Show();
    } //MyApplicationContext

    private void OnApplicationExit(Object sender,
 EventArgs e)
    {
        // When the application is exiting, write the application data
 to the
        // user file and close it.
        WriteFormDataToFile();
        try {
            // Ignore any errors that might occur while closing the file
 handle.
            userData.Close();
        }
        catch (System.Exception exp) {
        }
    } //OnApplicationExit

    private void OnFormClosing(Object sender,
 CancelEventArgs e)
    {
        // When a form is closing, remember the form position so it
        // can be saved in the user data file.
        if (sender instanceof AppForm1) {
            form1Position = ((Form)sender).get_Bounds();
        }
        else {
            if (sender instanceof AppForm2) {
                form2Position = ((Form)sender).get_Bounds();
            }
        }
    } //OnFormClosing

    private void OnFormClosed(Object sender,
 EventArgs e)
    {
        // When a form is closed, decrement the count of open forms.
        // When the count gets to 0, exit the app by calling
        // ExitThread().
        formCount--;
        if (formCount == 0) {
            ExitThread();
        }
    } //OnFormClosed

    private boolean WriteFormDataToFile()
    {
        // Write the form positions to the file.
        UTF8Encoding encoding = new UTF8Encoding();
        RectangleConverter rectConv = new RectangleConverter();
        String form1Pos = rectConv.ConvertToString(form1Position);
        String form2Pos = rectConv.ConvertToString(form2Position);
        ubyte dataToWrite[] = encoding.GetBytes("~" + form1Pos + "~"
 
            + form2Pos);

        try {
            // Set the write position to the start of the file and write
            userData.Seek(0, SeekOrigin.Begin);
            userData.Write(dataToWrite, 0, dataToWrite.length);
            userData.Flush();
            userData.SetLength(dataToWrite.length);
            return true;
        }
        catch (System.Exception exp) {
            // An error occurred while attempting to write, return false.
            return false;
        }
    } //WriteFormDataToFile

    private boolean ReadFormDataFromFile()
    {
        // Read the form positions from the file.
        UTF8Encoding encoding = new UTF8Encoding();
        String data;

        if (userData.get_Length() != 0) {
            ubyte dataToRead[] = new ubyte[(int)userData.get_Length()];

            try {
                // Set the read position to the start of the file and
 read.
                userData.Seek(0, SeekOrigin.Begin);
                userData.Read(dataToRead, 0, dataToRead.length);
            }
            catch (IOException e) {
                String errorInfo = e.ToString();

                // An error occurred while attempt to read, return false.
                return false;
            }

            // Parse out the data to get the window rectangles
            data = encoding.GetString(dataToRead);
            try {
                // Convert the string data to rectangles
                RectangleConverter rectConv = new RectangleConverter();
                String form1Pos = data.Substring(1, data.IndexOf("~", 1)
 - 1);
                form1Position = 
                    (Rectangle)(rectConv.ConvertFromString(form1Pos));

                String form2Pos = data.Substring(data.IndexOf("~", 1) +
 1);
                form2Position = 
                    (Rectangle)(rectConv.ConvertFromString(form2Pos));
                return true;
            }
            catch (System.Exception exp) {
                // Error occurred while attempting to convert the rectangle
 data.
                // Return false to use default values.
                return false;
            }
        }
        else {
            // No data in the file, return false to use default values.
            return false;
        }
    } //ReadFormDataFromFile

    /** @attribute STAThread()
     */
    public static void main(String[]
 args)
    {
        // Create the MyApplicationContext, that derives from
        // ApplicationContext, that manages when the application should
 exit.
        MyApplicationContext context = new MyApplicationContext();

        // Run the application with the specific context. It will exit
 when
        // all forms are closed.
        Application.Run(context);
    } //main 
} //MyApplicationContext
継承階層継承階層
System.Object
  System.Windows.Forms.ApplicationContext
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ApplicationContext コンストラクタ ()


ApplicationContext コンストラクタ (Form)

Form指定して、ApplicationContext クラス新しインスタンス初期化します。

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

Public Sub New ( _
    mainForm As Form _
)
Dim mainForm As Form

Dim instance As New ApplicationContext(mainForm)
public ApplicationContext (
    Form mainForm
)
public:
ApplicationContext (
    Form^ mainForm
)
public ApplicationContext (
    Form mainForm
)
public function ApplicationContext (
    mainForm : Form
)

パラメータ

mainForm

コンテキストとして使用するアプリケーションメイン Form

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

ApplicationContext コンストラクタ

ApplicationContext クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
ApplicationContext () コンテキスト指定せずに ApplicationContext クラス新しインスタンス初期化します。
ApplicationContext (Form) Form指定してApplicationContext クラス新しインスタンス初期化します。
参照参照

関連項目

ApplicationContext クラス
ApplicationContext メンバ
System.Windows.Forms 名前空間

ApplicationContext プロパティ


ApplicationContext メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ApplicationContext クラス
System.Windows.Forms 名前空間

ApplicationContext メンバ

アプリケーション スレッドに関するコンテキスト情報指定します

ApplicationContext データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ApplicationContext オーバーロードされます。 ApplicationContext クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
パブリック イベントパブリック イベント
  名前 説明
パブリック イベント ThreadExit ExitThread を呼び出したことにより、スレッドメッセージ ループ終了したときに発生します
参照参照

関連項目

ApplicationContext クラス
System.Windows.Forms 名前空間



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

辞書ショートカット

すべての辞書の索引

「ApplicationContext」の関連用語

ApplicationContextのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS