vb.net按esc退出 vb退出按钮

vb编程时Esc键不能退出窗体将窗体vb.net按esc退出的属性KeyPreview设置为True:
Option
Explicit
Private
Sub
Form_KeyPress(KeyAscii
As
Integer)
If
KeyAscii
=
27
Then
'如果按的键是Escvb.net按esc退出,
End
'那么退出程序
End
If
End
Sub
Private
Sub
Form_Load()
Me.KeyPreview
=
True
End
【vb.net按esc退出 vb退出按钮】Sub
vb怎样表示“长按”某个键,如ESC退出键?'窗体获得焦点才有效,如果无焦点可以使用api函数,自己修改
Option Explicit
Const settime = 1 '这里设置延迟1s
Dim keyup As Boolean, keydown As Boolean
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 And Not keydown Then
keyup = False
keydown = True
delaymessage
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then
keyup = True
keydown = False
End If
End Sub
Function delaymessage()
Dim t, flag As Boolean
t = Timer
Do
If keyup Then Exit Do '未到时间放掉Esc键
If Timer - t = settime Then
flag = True
Exit Do
End If
DoEvents
Loop
If flag Then
Print "时间已到:"settime '可以用msgbox,但由于长安esc后msgbox显示后马上又消失,这里只是一个功能,给你用print做显示
flag = False
End If
End Function
vb.net一键关闭显示器Public Class Form1
System.Runtime.InteropServices.DllImport("user32.dll") _
Private Shared Function SendMessage(ByVal hWnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Const SC_MONITORPOWER As Integer = HF170
Const WM_SYSCOMMAND As Integer = H112
Private Enum MonitorMode As Integer
[ON] = -1
STANBY = 1
OFF = 2
End Enum
Private Sub ChangeMonitorState(ByVal mode As MonitorMode)
SendMessage(-1, WM_SYSCOMMAND, SC_MONITORPOWER, CInt(mode))
End Sub
Private Sub Off()
ChangeMonitorState(MonitorMode.OFF)
End Sub
Private Sub [On]()
ChangeMonitorState(MonitorMode.[ON])
End Sub
Private Sub StandBy()
ChangeMonitorState(MonitorMode.STANBY)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Off()
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then [On]()
End Sub
End Class
按button1按钮关闭显示器,按Esc键打开显示器
VB如何按下Esc快速退出当前运行的游戏1,建立一个菜单项
2,在菜单编辑器中设置这个菜单项不显示
3,在菜单编辑器中设置这个菜单项vb.net按esc退出的快捷键是ESC.
4,在这个菜单项vb.net按esc退出的代码中,输入结束程序vb.net按esc退出的代码.
关于vb.net按esc退出和vb退出按钮的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读