Application.UserAppDataPath プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Application.UserAppDataPath プロパティの意味・解説 

Application.UserAppDataPath プロパティ

ユーザーアプリケーション データパス取得します

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

Public Shared ReadOnly Property
 UserAppDataPath As String
Dim value As String

value = Application.UserAppDataPath
public static string UserAppDataPath
 { get; }
public:
static property String^ UserAppDataPath {
    String^ get ();
}
/** @property */
public static String get_UserAppDataPath ()

プロパティ
ユーザーアプリケーション データパス

解説解説
使用例使用例

2 つフォーム表示し両方フォーム閉じられたときにアプリケーション終了するコード例を、次に示しますアプリケーション開始時と終了時に、各フォーム位置記憶されます。この例では、UserAppDataPath プロパティ使用してユーザーアプリケーション データ格納します

MyApplicationContext クラスは、ApplicationContext の継承クラスで、各フォームがいつ閉じられたのかを追跡し両方フォーム閉じられたときに現在のスレッド終了します。このクラスは、ユーザー代わりにフォーム位置格納しますフォーム位置データは、Appdata.txt という名前のファイル格納されます。このファイルは、UserAppDataPath指定された場所に作成されます。Main メソッドは、Application.Run(context)呼び出すことにより、ApplicationContext指定してアプリケーション起動します。

このコードは、ApplicationContext クラス概要紹介されている例からの抜粋です。簡略にするため、コード一部示されていません。コード全体については、ApplicationContext参照してください

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 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 {}
}
   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:

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「Application.UserAppDataPath プロパティ」の関連用語

Application.UserAppDataPath プロパティのお隣キーワード
検索ランキング

   

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



Application.UserAppDataPath プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS