vb.net的windows窗体实现dos命令__教程 |
|
日期:2007-5-20 1:23:26 人气:82 [大 中 小] |
|
|
|
err.stream.Close() End If
End Sub
Private Sub btClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btClear.Click Me.tbResult.Text = String.Empty End Sub
Private Sub btnExcute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExcute.Click Me.CmdExcute() End Sub
Private Sub CmdExcute() Try Me.Cursor = System.Windows.Forms.Cursors.WaitCursor If Me.tbComText.Text <> "" Then sw.WriteLine(Me.tbComText.Text) Else sw.WriteLine("Dir") End If Me.Cursor = System.Windows.Forms.Cursors.Default
'向combobox中添加元素 Me.tbComText.Items.Add(Me.tbComText.Text) Me.tbComText.SelectionStart = 0 Me.tbComText.SelectionLength = Me.tbComText.Text.Length Me.tbComText.Focus() Catch ex As Exception MsgBox("CmdExcute--" & ex.ToString) End Try End Sub
Private Sub AppText(ByVal strAdd As String) Me.tbResult.Text &= strAdd End Sub
'回调函数 '为了保证执行invoke方法的线程顺序,使用了MethodImpl <MethodImpl(MethodImplOptions.Synchronized)> _ Sub CBstream(ByVal s As IAsyncResult) Try Dim t As MyStreamReader = CType(s.AsyncState, MyStreamReader) If t.stream.BaseStream Is Nothing Then Exit Sub End If Dim i As Integer = t.stream.BaseStream.EndRead(s) Dim strReceive As String = System.Text.Encoding.Default.GetString(t.bytes, 0, i) Me.Invoke(New TextAddHandler(AddressOf AppText), New Object() {strReceive}) t.stream.BaseStream.BeginRead(t.bytes, 0, 1024, New AsyncCallback(AddressOf CBstream), t) Catch ex As Exception MsgBox("CBstream--" & ex.ToString) End Try End Sub
Friend Class MyStreamReader Public stream As IO.StreamReader Public bytes(1024) As Byte Public Sub New() End Sub End Class End Class |
|
出处:本站原创 作者:佚名 |
|
|