走近VB.NET十六 SendKeys方法与Shell函数

王朝vb·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

走近VB.NET十六 SendKeys方法与Shell函数

hejianzhong http://www.yescnet.com

VB.Net中使用Sendkeys遥控:

大家在VB6中都用过sendkeys,幕通过发送键盘的事件间接地控制外部程序,是有遥控之说。

我在VB7中却发现这个不能用了, 也就不了了之,

后来一次在查阅MSDN的时候竟看到了这个,是以尝试了一下,竟然旧貌新颜,还是一样好用。

主要是在system.winforms族中找到sendkeys 使用方法同VB6

键:一般的字符键如下输入”A” “B” “C”………………”Z”等,如果要连续按下两个以上就使用”AB”的形式

如果同时按下AB就使用括号如”(AB)”

如果是功能键,就放到大括号中如“{F4}” 另:用+代表Shift,用^代表Ctrl,用%代表Alt

如“+A”表示按下Shift同时按A

下面是一个例子:

Dim sdstr As System.WinForms.SendKeys

sdstr.Send("%{F4}") 发送ALT+F4

下面这个代码在按下Button2以后转移焦点到下一个控件,

使按钮能按下又不能按受焦点.

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim sdstr As System.WinForms.SendKeys

sdstr.Send("{TAB}")

End Sub

下面使用SendWait,使用的方法同上,不过执行这个过程会等待到发送的键执行完成以后,再继续执行后面的代码.

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim sdstr As System.WinForms.SendKeys

'sdstr.Send("{TAB}")

sdstr.SendWait("{TAB}")

End Sub

VB.NET中使用shell调用外部程序:

Shell(pathname as string,[style as microsoft.visualbasic.appwinstyle=2],[wait as boolean=false],[timeout as integer=-1]) as integer

调用资源管理器

Dim PID As Integer

PID = Shell("explorer.exe http://vbnetcn.126.com", Microsoft.VisualBasic.AppWinStyle.NormalFocus, True)

调用默认程序

Dim PID As Integer

PID = Shell("start.exe mailto:vbnetcn@163.com", Microsoft.VisualBasic.AppWinStyle.Hide, True)

使用Microsoft.VisualBasic.AppWinStyle.Hide参数是为了隐藏程序运行时跳出的DOS窗口。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航