扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
见下面的代码
创新互联是一家集网站建设,藁城企业网站建设,藁城品牌网站建设,网站定制,藁城网站建设报价,网络营销,网络优化,藁城网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
Public Class Form1
Public Declare Auto Function RegisterHotKey Lib "user32.dll" Alias "RegisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean
Public Declare Auto Function UnRegisterHotKey Lib "user32.dll" Alias "UnregisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer) As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'注册全局热键
RegisterHotKey(Handle, 0, 0, Keys.F4)
'第3个参数意义: 0=nothing 1 -alt 2-ctrl 3-ctrl+alt 4-shift 5-alt+shift 6-ctrl+shift 7-ctrl+shift+alt
End Sub
Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
UnRegisterHotKey(Handle, 0)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = 786 Then
Me.Activate()
End If
MyBase.WndProc(m)
End Sub
End Class
不能,自己写个小的windows窗体Form2,
添上textbox,然后
Dim f As New Form(Form2)
f.topmost=true
f.ShowDialog()
2个函数的参数不一样 msgbox是vb6的 messagebox.show是vb.net的 基本功能都是一样的
vb.net可能就多一个文本的排列方式 左右对齐 msgbox 没有
可以在客户端注入脚本,如:
ClientScript.RegisterStartupScript(typeof(Page), "ScriptKey", "script type=\"text/javascript\" language=\"javascript\"window.alert("+你的异常信息+");/script");
还有就是捕获异常可以用
try
{
}
catch(Exception e)
{
throw new Exception(e.Message);
}
以下内容为网络提供,但我自己验证可行,供你参考.
Imports System.IO
Public Class Form1
Public Const WM_DEVICECHANGE = H219
Public Const DBT_DEVICEARRIVAL = H8000
Public Const DBT_CONFIGCHANGECANCELED = H19
Public Const DBT_CONFIGCHANGED = H18
Public Const DBT_CUSTOMEVENT = H8006
Public Const DBT_DEVICEQUERYREMOVE = H8001
Public Const DBT_DEVICEQUERYREMOVEFAILED = H8002
Public Const DBT_DEVICEREMOVECOMPLETE = H8004
Public Const DBT_DEVICEREMOVEPENDING = H8003
Public Const DBT_DEVICETYPESPECIFIC = H8005
Public Const DBT_DEVNODES_CHANGED = H7
Public Const DBT_QUERYCHANGECONFIG = H17
Public Const DBT_USERDEFINED = HFFFF
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DEVICECHANGE Then
Select Case m.WParam
Case WM_DEVICECHANGE
Case DBT_DEVICEARRIVAL 'U盘插入
ComboBox1.Items.Clear()
Dim s() As DriveInfo = DriveInfo.GetDrives
For Each drive As DriveInfo In s
If drive.DriveType = DriveType.Removable Then
ListBox1.Items.Add("U盘已插入!盘符为:" + drive.Name.ToString())
ComboBox1.Items.Add(drive.Name)
End If
Next
BtnWrite.Enabled = True
BtnRead.Enabled = True
Case DBT_CONFIGCHANGECANCELED
Case DBT_CONFIGCHANGED
Case DBT_CUSTOMEVENT
Case DBT_DEVICEQUERYREMOVE
Case DBT_DEVICEQUERYREMOVEFAILED
Case DBT_DEVICEREMOVECOMPLETE 'U盘卸载
ListBox1.Items.Add("U盘卸载!")
BtnWrite.Enabled = False
BtnRead.Enabled = False
Case DBT_DEVICEREMOVEPENDING
Case DBT_DEVICETYPESPECIFIC
Case DBT_DEVNODES_CHANGED
Case DBT_QUERYCHANGECONFIG
Case DBT_USERDEFINED
End Select
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add("请您现在插入U盘至USB接口!")
End Sub
Private Sub BtnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnWrite.Click
If ComboBox1.Text = "" Then
MsgBox("请选择U盘盘符!", MsgBoxStyle.Exclamation, "Warn")
Else
Dim Writer As StreamWriter = Nothing
Try
Dim fileName As String = ComboBox1.Text + "Test.txt"
Writer = New StreamWriter(fileName)
Writer.WriteLine(InputBox("老四,请输入要保存的字符串", "输入信息", "Input then Test String! hehe!"))
MsgBox("Write to " + fileName + " Success!")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Write 失败")
Finally
If Writer IsNot Nothing Then Writer.Close()
End Try
End If
End Sub
Private Sub BtnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRead.Click
If ComboBox1.Text = "" Then
MsgBox("请选择U盘盘符!", MsgBoxStyle.Exclamation, "Warn")
Else
Dim Reader As StreamReader = Nothing
Try
Dim fileName As String = ComboBox1.Text + "Test.txt"
Reader = New StreamReader(fileName)
MsgBox("Read from " + fileName + vbCrLf + Reader.ReadToEnd, MsgBoxStyle.Information, "Info")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Read 失败")
Finally
If Reader IsNot Nothing Then Reader.Close()
End Try
End If
End Sub
End Class
在我的XP+VB2010环境下,测试U盘插入拔出,没有问题:
Private WM_DEVICECHANGE As Integer = H219
Public Enum WM_DEVICECHANGE_WPPARAMS As Integer
DBT_CONFIGCHANGECANCELED = H19
DBT_CONFIGCHANGED = H18
DBT_CUSTOMEVENT = H8006
DBT_DEVICEARRIVAL = H8000
DBT_DEVICEQUERYREMOVE = H8001
DBT_DEVICEQUERYREMOVEFAILED = H8002
DBT_DEVICEREMOVECOMPLETE = H8004
DBT_DEVICEREMOVEPENDING = H8003
DBT_DEVICETYPESPECIFIC = H8005
DBT_DEVNODES_CHANGED = H7
DBT_QUERYCHANGECONFIG = H17
DBT_USERDEFINED = HFFFF
End Enum
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DEVICECHANGE Then
Select Case m.WParam
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEARRIVAL
MsgBox("USB device is just plugged in!")
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEREMOVECOMPLETE
MsgBox("USB device is just taken out")
End Select
End If
MyBase.WndProc(m)
End Sub
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流