タイトル : Re^3: ShowDialog時の処理について 投稿日 : 2008/09/02(Tue) 10:05 投稿者 : たくボン
返信遅くなりすいません。開発環境は何でしょうか? VS2005以降ならBackgroundWoker, それ以前なら別スレッドで処理するのが良いと思います。 以下は、VB2005でのサンプルの手順です。 -- 作成手順 --------- 新規プロジェクト作成。 Form1, Form2を作成。 Form1にLabel1とBackgroundWoker1, Button1, Button2を追加。 BackgroundWoker1のWokerReportsProgressをTrueに。 Form1に以下のコードを追加。 Private sec As Integer Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Do If DateTime.Now.Second <> sec Then BackgroundWorker1.ReportProgress(1) End If Application.DoEvents() Loop End Sub Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged Me.Label1.Text = DateTime.Now.Second End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.BackgroundWorker1.RunWorkerAsync() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim dlg As New Form2 If dlg.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then 'TODO hoge End If End Sub ------------------ 2005からはスレッド間のコントロールアクセスで例外が発生するようになったので、BackgroudWokerを利用するのが簡単でいいです。 |