您的位置:首页 > 运维架构 > Shell

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

2008-05-01 05:26 393 查看
走近VB.NET十六 SendKeys方法Shell函数hejianzhong NET.com">http://www.yescNET.comVB.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:// href="http://www.66of.com" target=_blank>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窗口。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: