为了美化或自定义窗体,通常会把窗体做成无边框形式,使用无边框窗体会存在一些问题的,以vb为例,当窗体borderstyle设置为0时,会出现以下问题:1.任务栏不再出现程序图标 2.窗体无法拖行移动 3.窗体无法拖动缩放,此文针对这些问题给出解决方案
问题一:
问题描述: 任务栏不显示程序图标
问题分析:此问题是因为vb6在窗体borderstyle设置为0时,会自动将showintask属性改为false
解决方案:在属性面板将showintask属性改为true即可
问题二:
问题描述:窗体无法拖动实现移动
解决方案:此问题解决方案有两种
方案1:原生实现
在form_mousemove事件下,当按下左键并拖动时,窗体自行进行+鼠标移动的X和Y,具体代码如下
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then Me.Move Me.Left + X + 45, Me.Top + Y + 45 End Sub用此方法如果出现不跟手的情况,可以参考方案2的api实现
'''声明API''' private Declare Function ReleaseCapture Lib "user32" () As Long private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) ReleaseCapture SendMessage Me.hWnd, &HA1, 2, 0& End Sub
问题三:
问题描述:窗体无法拖动实现移动
解决方案:
'''API声明''' 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 Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long '''常量声明''' private Const GWL_STYLE = (-16) private Const WS_THICKFRAME = &H40000 private Const SWP_NOMOVE = &H2 '不移动窗体 private Const SWP_NOSIZE = &H1 '不改变窗体尺寸 private Const SWP_DRAWFRAME = &H20 private Const SWP_NOZORDER = &H4 Sub form_load() hwnd=me.hwnd dwStyle = GetWindowLong(hwnd, GWL_STYLE) If SetTrue Then dwStyle = dwStyle Or WS_THICKFRAME dwStyle = SetWindowLong(hwnd, GWL_STYLE, dwStyle) SetWindowPos hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME End Sub此方法是通过windows的api给form画一个边框