Application.DoEvents メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Application.DoEvents メソッドの意味・解説 

Application.DoEvents メソッド

メッセージ キューに現在ある Windows メッセージをすべて処理します

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

Public Shared Sub DoEvents
Application.DoEvents
public:
static void DoEvents ()
解説解説
使用例使用例

DoEvents メソッド使用するコード例次に示します。このコード実行すると、ユーザーは OpenFileDialog からグラフィックス ファイル選択できます選択したファイルフォーム表示されます。DoEvents メソッド働きにより、フォーム開かれるグラフィックス ファイルごとに再描画されます。この例を実行するには、PictureBox1 という名前の PictureBox、OpenFileDialog1 という名前の OpenFileDialog、および fileButton という名前のボタン配置されているフォーム次のコード貼り付けます。次にフォームコンストラクタまたは Load メソッドから、InitializePictureBox メソッドInitializeOpenFileDialog メソッド呼び出します。またこの例では、Button コントロールの Control.Click イベントおよび OpenFileDialog の FileOk イベントが、この例で定義されているイベント ハンドラ関連付けられている必要があります。このコード実行開始したら、ボタンクリックしてダイアログ ボックス表示します

Private Sub InitializePictureBox()
    Me.PictureBox1 = New System.Windows.Forms.PictureBox
    Me.PictureBox1.BorderStyle = _
        System.Windows.Forms.BorderStyle.FixedSingle
    Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    Me.PictureBox1.Location = New System.Drawing.Point(72,
 112)
    Me.PictureBox1.Name = "PictureBox1"
    Me.PictureBox1.Size = New System.Drawing.Size(160,
 136)
    Me.PictureBox1.TabStop = False
End Sub

Private Sub InitializeOpenFileDialog()
    Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog

    ' Set the file dialog to filter for graphics files.
    Me.OpenFileDialog1.Filter = _
    "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"

    ' Allow the user to select multiple images.
    Me.OpenFileDialog1.Multiselect = True
    Me.OpenFileDialog1.Title = "My Image Browser"
End Sub

Private Sub fileButton_Click(ByVal
 sender As System.Object, _
    ByVal e As System.EventArgs) Handles
 FileButton.Click
    OpenFileDialog1.ShowDialog()
End Sub


' This method handles the FileOK event.  It opens each file 
' selected and loads the image from a stream into PictureBox1.
Private Sub OpenFileDialog1_FileOk(ByVal
 sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs)
 _
 Handles OpenFileDialog1.FileOk

    Me.Activate()
    Dim file, files() As String
    files = OpenFileDialog1.FileNames

    ' Open each file and display the image in PictureBox1.
    ' Call Application.DoEvents to force a repaint after each
    ' file is read.        
    For Each file In files
        Dim fileInfo As System.IO.FileInfo
 = New System.IO.FileInfo(file)
        Dim fileStream As System.IO.FileStream
 = fileInfo.OpenRead()
        PictureBox1.Image = System.Drawing.Image.FromStream(fileStream)
        Application.DoEvents()
        fileStream.Close()

        ' Call Sleep so the picture is briefly displayed, 
        'which will create a slide-show effect.
        System.Threading.Thread.Sleep(2000)
    Next
    PictureBox1.Image = Nothing
End Sub

private void InitializePictureBox()
{
    this.PictureBox1 = new System.Windows.Forms.PictureBox();
    this.PictureBox1.BorderStyle = 
        System.Windows.Forms.BorderStyle.FixedSingle;
    this.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    this.PictureBox1.Location = new System.Drawing.Point(72,
 112);
    this.PictureBox1.Name = "PictureBox1";
    this.PictureBox1.Size = new System.Drawing.Size(160,
 136);
    this.PictureBox1.TabIndex = 6;
    this.PictureBox1.TabStop = false;
}

private void InitializeOpenFileDialog()
{
    this.OpenFileDialog1 = new System.Windows.Forms.OpenFileDialog();

    // Set the file dialog to filter for graphics files.
    this.OpenFileDialog1.Filter = 
        "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" + 
        "All files (*.*)|*.*";

    // Allow the user to select multiple images.
    this.OpenFileDialog1.Multiselect = true;
    this.OpenFileDialog1.Title = "My Image Browser";
    
}

private void fileButton_Click(System.Object
 sender, System.EventArgs e)
{
    OpenFileDialog1.ShowDialog();
}


// This method handles the FileOK event.  It opens each file 
// selected and loads the image from a stream into PictureBox1.
private void OpenFileDialog1_FileOk(object
 sender, 
    System.ComponentModel.CancelEventArgs e)
{

    this.Activate();
     string[] files = OpenFileDialog1.FileNames;

    // Open each file and display the image in PictureBox1.
    // Call Application.DoEvents to force a repaint after each
    // file is read.        
    foreach (string file in
 files )
    {
        System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);
        System.IO.FileStream fileStream = fileInfo.OpenRead();
        PictureBox1.Image = System.Drawing.Image.FromStream(fileStream);
        Application.DoEvents();
        fileStream.Close();

        // Call Sleep so the picture is briefly displayed, 
        //which will create a slide-show effect.
        System.Threading.Thread.Sleep(2000);
    }
    PictureBox1.Image = null;
}
void InitializePictureBox()
{
   this->PictureBox1 = gcnew System::Windows::Forms::PictureBox;
   this->PictureBox1->BorderStyle =
      System::Windows::Forms::BorderStyle::FixedSingle;
   this->PictureBox1->SizeMode = PictureBoxSizeMode::StretchImage;
   this->PictureBox1->Location = System::Drawing::Point(
 72, 112 );
   this->PictureBox1->Name = "PictureBox1";
   this->PictureBox1->Size = System::Drawing::Size( 160,
 136 );
   this->PictureBox1->TabIndex = 6;
   this->PictureBox1->TabStop = false;
}

void InitializeOpenFileDialog()
{
   this->OpenFileDialog1 = gcnew System::Windows::Forms::OpenFileDialog;
   
   // Set the file dialog to filter for graphics files.
   this->OpenFileDialog1->Filter =
      "Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" +
      "All files (*.*)|*.*";
   
   // Allow the user to select multiple images.
   this->OpenFileDialog1->Multiselect = true;
   this->OpenFileDialog1->Title = "My Image Browser";
}

void fileButton_Click( System::Object^ sender, System::EventArgs^
 e )
{
   OpenFileDialog1->ShowDialog();
}

// This method handles the FileOK event.  It opens each file 
// selected and loads the image from a stream into PictureBox1.
void OpenFileDialog1_FileOk( Object^ sender,
   System::ComponentModel::CancelEventArgs^ e )
{
   this->Activate();
   array<String^>^ files = OpenFileDialog1->FileNames;
   
   // Open each file and display the image in PictureBox1.
   // Call Application.DoEvents to force a repaint after each
   // file is read.        
   for each ( String^ file in files )
   {
      System::IO::FileInfo^ fileInfo = gcnew System::IO::FileInfo( file );
      System::IO::FileStream^ fileStream = fileInfo->OpenRead();
      PictureBox1->Image = System::Drawing::Image::FromStream( fileStream );
      Application::DoEvents();
      fileStream->Close();
      
      // Call Sleep so the picture is briefly displayed, 
      //which will create a slide-show effect.
      System::Threading::Thread::Sleep( 2000 );
   }
   PictureBox1->Image = nullptr;
}
private void InitializePictureBox()
{
    this.pictureBox1 = new System.Windows.Forms.PictureBox();
    this.pictureBox1.set_BorderStyle(
        System.Windows.Forms.BorderStyle.FixedSingle);
    this.pictureBox1.set_SizeMode(PictureBoxSizeMode.StretchImage);
    this.pictureBox1.set_Location(new System.Drawing.Point(72,
 112));
    this.pictureBox1.set_Name("pictureBox1");
    this.pictureBox1.set_Size(new System.Drawing.Size(160,
 136));
    this.pictureBox1.set_TabIndex(6);
    this.pictureBox1.set_TabStop(false);
} //InitializePictureBox

private void InitializeOpenFileDialog()
{
    this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
    // Set the file dialog to filter for graphics files.
    this.openFileDialog1.set_Filter("Images (*.BMP;*.JPG;*.GIF)|"
 
        + "*.BMP;*.JPG;*.GIF|All files (*.*)|*.*");
    // Allow the user to select multiple images.
    this.openFileDialog1.set_Multiselect(true);
    this.openFileDialog1.set_Title("My Image Browser");
} //InitializeOpenFileDialog

private void fileButton_Click(Object sender,
 System.EventArgs e)
{
    openFileDialog1.ShowDialog();
} //fileButton_Click

// This method handles the FileOK event. It opens each file 
// selected and loads the image from a stream into pictureBox1.
private void openFileDialog1_FileOk(Object
 sender, 
    System.ComponentModel.CancelEventArgs e)
{
    this.Activate();
    String files[] = openFileDialog1.get_FileNames();
    // Open each file and display the image in pictureBox1.
    // Call Application.DoEvents to force a repaint after each
    // file is read.
    for (int iCtr = 0; iCtr < files.length;
 iCtr++) {
        String file = files[iCtr];
        System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);
        System.IO.FileStream fileStream = fileInfo.OpenRead();
        pictureBox1.set_Image(System.Drawing.Image.FromStream(fileStream));
        Application.DoEvents();
        fileStream.Close();
        // Call Sleep so the picture is briefly displayed, 
        // which will create a slide-show effect.
        System.Threading.Thread.Sleep(2000);
    }
    pictureBox1.set_Image(null);
} //openFileDialog1_FileOk
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「Application.DoEvents メソッド」の関連用語

Application.DoEvents メソッドのお隣キーワード
検索ランキング

   

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



Application.DoEvents メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS