日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
VB.NETSendKeys方法與鍵入值

VB.NET有很多值得學習的地方,這里我們主要介紹VB.NET SendKeys方法,包括介紹控制過程輸入輸出等方面。

創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站設計、成都網(wǎng)站建設與策劃設計,旬陽網(wǎng)站建設哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設十多年,網(wǎng)設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:旬陽等地區(qū)。旬陽做網(wǎng)站價格咨詢:18980820575

有時候,你可能不僅僅想使用簡單的命令行,而是想把更復雜的輸入信息直接發(fā)送到啟動的過程中。前面例子中的把輸出導入到文件中的方法,并不總是最好的選擇。在許多情況下,把輸出直接導回你的應用程序可能更有效。對于使用StdIn、StdOut和StdErr的程序,比如控制臺應用程序,你可以覆蓋默認方法,提供一個StreamWriter來輸入,并提供一個StreamReaders來讀取StdOut和StdErr輸出值。當你啟動過程的時候,你需要設置ProcessStartInfo對象的RedirectStandardInput、RedirectStandardOutput和 RedirectStandardError屬性為True。然后,在啟動過程之后,使用Process對象的StandardInput、StandardOutput和StandardError屬性來把輸入輸出流分配到StreamReader和StreamWriter對象。

警告:默認情況下,框架使用Win32 ShellExecute函數(shù),在內(nèi)部啟動過程;但是當你想再分配輸入輸出流的時候,你必須在啟動過程之前設置 ProcessStartInfo.UseShellExecute屬性為False。注意當你那么做的時候,你必須要么指定到文件的完全路徑,要么文件位置必須在環(huán)境路徑中。例如,下面的代碼創(chuàng)建一個不可見的窗口,取得系統(tǒng)目錄中.com文件的目錄列表,然后在一個消息框中顯示結果。

 
 
 
  1. Dim myProcess As Process = New Process()  
  2. Dim s As String  
  3. myProcess.StartInfo.FileName = "cmd.exe" 
  4. myProcess.StartInfo.UseShellExecute = False 
  5. myProcess.StartInfo.CreateNoWindow = True 
  6. myProcess.StartInfo.RedirectStandardInput = True 
  7. myProcess.StartInfo.RedirectStandardOutput = True 
  8. myProcess.StartInfo.RedirectStandardError = True 
  9. myProcess.Start()  
  10. Dim sIn As StreamWriter = myProcess.StandardInput  
  11. sIn.AutoFlush = True 
  12.  
  13. Dim sOut As StreamReader = myProcess.StandardOutput  
  14. Dim sErr As StreamReader = myProcess.StandardError  
  15. sIn.Write("dir c:\Windows\system32\*.com" & _  
  16. System.Environment.NewLine)  
  17. sIn.Write("exit" & System.Environment.NewLine)  
  18. s = sOut.ReadToEnd()  
  19. If Not myProcess.HasExited Then  
  20. myProcess.Kill()  
  21. End If  
  22.  
  23. MessageBox.Show("The 'dir' command window was " & _  
    closed at: " & myProcess.ExitTime & "." & _  
    System.Environment.NewLine & "Exit Code: " & _  myProcess.ExitCode)  
  24.  
  25. sIn.Close()  
  26. sOut.Close()  
  27. sErr.Close()  
  28. myProcess.Close()  
  29. MessageBox.Show(s) 

對于不使用StdIn的程序,你可以使用VB.NET SendKeys方法來輸入按鍵事件。例如,下面這些代碼啟動記事本并輸入一些文本。

 
 
 
  1. Dim myProcess As Process = New Process()  
  2. myProcess.StartInfo.FileName = "notepad" 
  3. myProcess.StartInfo.WindowStyle = _ 
  4. ProcessWindowStyle.Normal  
  5. myProcess.EnableRaisingEvents = True 
  6. AddHandler myProcess.Exited, _  
  7. AddressOf Me.SendKeysTestExited  
  8. myProcess.Start()  
  9.  
  10. myProcess.WaitForInputIdle(1000)  
  11. If myProcess.Responding Then  
  12. System.Windows.Forms.SendKeys.SendWait( _  
  13. "This text was entered using the " & _  
  14. "System.Windows.Forms.SendKeys method.")  
  15. Else  
  16. myProcess.Kill()  
  17. End If  

你可以使用VB.NET SendKeys方法發(fā)送任何鍵入值,包括Alt、Ctrl和Shift鍵;所以,你可以使用它來保存或載入文件、退出或者執(zhí)行其他菜單驅(qū)動的命令。然而、VB.NET SendKeys方法只發(fā)送鍵入值到活動窗口(就是有焦點的那個窗口),所以如果一個應用程序在這個過程中失去焦點,那么可能會出現(xiàn)問題。

【編輯推薦】

  1. 簡單講述VB.NET表間拖放
  2. 五分鐘學會VB.NET實現(xiàn)拖放
  3. 講述強大的VB.NET Web Forms,使用起來卻如此簡單
  4. 分析VB QuickSort應用程序
  5. 兩步就可以掌握VB使用ArrayList類

網(wǎng)站題目:VB.NETSendKeys方法與鍵入值
URL鏈接:http://www.5511xx.com/article/djceoed.html