
这里打算收集vb.net 窗体设计的常用技巧,用的时候不至于每次都从头来过
1.子窗口(体)在父窗口(体)居中
Dim tempRect As New Rectangle(frmM.Left + (frmM.Width - Me.Width) / 2, frmM.Top + (frmM.Height - Me.Height) / 2, 866, 537)
DesktopBounds = tempRect
备注:frmM是父窗口,最后的866,537分别为子窗口的宽度和高度
2.按ESC键退出
Private Sub form_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar = Chr(27) Then
Me.Close()
End If
End Sub
具体chr对应的数值,查标准ASCII表
3.tooltip用法
ToolTip1.SetToolTip(控件名, "字符")
4.vb.net 随windows开机启动
Dim StartupKey As Microsoft.Win32.RegistryKey
StartupKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
If chkAutoStart.Checked Then
StartupKey.SetValue("SiteM", Application.ExecutablePath & " -startup")
Else
StartupKey.DeleteValue("SiteM", False)
End If