Get Events Handle Form2
1.Create new button1
2.Add event handle
Example: Event button
Public Class Form1
Private form2 As New Form
Private button1 As New Button
Private proc As Process
Public Sub New()
MyBase.New()
InitializeComponent()
button1.Text = "RunApp"
button1.Location = New Point(100, 100)
button1.Cursor = Cursors.Hand
form2.Text = "Form2"
form2.Controls.Add(button1)
AddHandler button1.Click, AddressOf button1_Click
AddHandler form2.FormClosing, AddressOf form2_FormClosing
End Sub
Public Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim pList() As System.Diagnostics.Process = _
System.Diagnostics.Process.GetProcessesByName("calc")
Dim app As String = Nothing
For Each proc As System.Diagnostics.Process In pList
app = proc.ProcessName
Next
If app = "calc" Then
Return
Else
proc = Process.Start("Calc.exe")
End If
End Sub
Public Sub form2_FormClosing(ByVal sender As Object, ByVal e As EventArgs)
Try
proc.Kill()
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
form2.StartPosition = FormStartPosition.CenterScreen
If form2.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.Dispose()
Else
Me.Close()
End If
End Sub
End Class