
正文
vb.net窗体停靠 vb窗体布局怎么设置
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net窗体靠屏幕边缘触发事件
建立新vb.net窗体停靠的formvb.net窗体停靠,加入一个timervb.net窗体停靠,interval设为100
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim p As POINTAPI
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = H2
Private Const SWP_NOSIZE = H1
Private Sub Form_Load()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE '加载窗口是指定窗口在最顶层
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
GetCursorPos p
If Me.Top = 0 Then 'form1 is not hide and form1's top is 0
'hide form
If p.Y Me.Height / 15 + Me.Top / 15 Or p.X Me.Width / 15 + Me.Left / 15 Or p.X Me.Left / 15 Then 'mouse is not over form1
Me.Top = 0 - Me.Height + 50
End If
'show form
If p.X Me.Left / 15 And p.X Me.Left / 15 + Me.Width / 15 And p.Y 3 Then 'mouse is over form
Me.Top = 0
End If
End If
If Me.Left = 0 Then ''form1 is not hide form1's left is 0
'hide form
If p.Y Me.Height / 15 + Me.Top / 15 Or p.Y Me.Top / 15 Or p.X Me.Width / 15 + Me.Left / 15 Then 'mouse is not over form1
Me.Left = 0 - Me.Width + 50
End If
'show form
If p.X 3 And p.Y Me.Top / 15 And p.Y Me.Height / 15 + Me.Top / 15 Then 'mouse is over form
Me.Left = 0
End If
End If
If Me.Left = Screen.Width - Me.Width Then
'hide form
If p.Y Me.Height / 15 + Me.Top / 15 Or p.Y Me.Top / 15 Or p.X Me.Left / 15 Then 'mouse is not over form1
Me.Left = Screen.Width - 50
End If
'show form
If p.X Screen.Width / 15 - 3 And p.Y Me.Top / 15 And p.Y Me.Height / 15 + Me.Top / 15 Then 'mouse is over form
Me.Left = Screen.Width - Me.Width
End If
End If
End Sub
相关问答
Q1: VB.NET怎么做永远停靠在屏幕上的东西
本质是一个不规则形状的窗体,把窗体的 TopMost 属性设为 True 即可。
Q2: vb.net在设计过程中,发现当窗口化的窗体最大化后,里面的组件不能被放大~~
这个问题,如有可能你应当先把大的控件停靠在窗体的某部分,其他的控件用form的resize事件触发控件宽高的数值或控件位置坐标的数值。例:
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Dim pLabel1, pTextBox1, pButton1 As New Point
pLabel1.X = CInt(Me.Width / 7)
pLabel1.Y = CInt(Me.Height / 8) + 4
pTextBox1.X = CInt(Me.Width / 5)
pTextBox1.Y = CInt(Me.Height / 8)
pButton1.X = CInt(Me.Width / 3)
pButton1.Y = CInt(Me.Height / 8) - 1
Me.Label1.Location = pLabel1
Me.TextBox1.Location = pTextBox1
Me.Button1.Location = pButton1
End Sub
以上只是改变了控件的位置,如需改变控件的大小,重新定义计算控件的size属性
Q3: VB.NET 可视化窗体应用程序设计的时候窗体在屏幕的位置
StartPosition属性有如下选项,分别含义如下:
CenterParent 窗体在其父窗体中居中。
CenterScreen 窗体在当前显示窗口中居中,其尺寸在窗体大小中指定。
Manual 窗体的位置由Location属性确定。
WindowsDefaultBounds 窗体定位在Windows默认位置,其边界也由Windows默认决定。
WindowsDefaultLocation 窗体定位在Windows默认位置,其尺寸在窗体大小中指定。
CenterScreen的意思并不是屏幕居中(是相对的),它是在"当前显示窗口"中居中。当用Show()方法时应选择CenterScreen,用ShowDialog()方法时应选择CenterParent,这样才能让要显示的窗口居中。
关于vb.net窗体停靠和vb窗体布局怎么设置的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






