C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


(過去ログ 18 を表示中)
■6875 / )  Re[4]: Control.Invokeが使えない件。
□投稿者/ えムナウ (82回)-(2007/08/25(Sat) 22:24:28)
元々Form2側ではClose後にTextBoxに表示する意味がないのですから、
以下のようにFormClosedイベントをひっかければいいと思いますが、
問題ありますでしょうか?

Public Class Form2
Inherits System.Windows.Forms.Form

Private Delegate Sub WriteLineDelegate(ByVal text As String)
Public MainForm As Form1
Public TextBox1 As TextBox
Public formClose As Boolean = False

Public Sub WriteLine(ByVal text As String)
If Not formClose Then
If Me.InvokeRequired Then
Me.Invoke(New WriteLineDelegate(AddressOf WriteLine), New Object() {text})
Else
Me.Text = text
Me.TextBox1.Text = text
Me.TextBox1.ScrollToCaret()
Me.TextBox1.Focus()
End If
End If
End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.components = New System.ComponentModel.Container
Dim Timer1 As New System.Windows.Forms.Timer(Me.components)
TextBox1 = New TextBox
Me.components.Add(Timer1)
Me.Controls.Add(TextBox1)
AddHandler Timer1.Tick, New EventHandler(AddressOf Timer1_Tick)
AddHandler Me.FormClosed, New FormClosedEventHandler(AddressOf Form2_FormClosed)
SyncLock MainForm.Form2SyncObject
MainForm.ChildFormCreated = True
End SyncLock
Timer1.Interval = New Random().Next(100, 1000)
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub

Private Sub Form2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
formClose = True
End Sub
End Class

返信 編集キー/


管理者用

- Child Tree -