求教:如何在VB.net中的form中不显示标题栏

eaqpi 2010-04-29 07:49:47
1、如题,如何在vb.net2008中显示没有标题栏的form。

...全文
170 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2010-04-29
  • 打赏
  • 举报
回复
Form的BorderStyle属性为0
设置Form属性的ControlBox=false
eaqpi 2010-04-29
  • 打赏
  • 举报
回复
这个代码有问题。
GetWindowRect(Me.Handle.ToInt32, tR)
返回错误了。


Public Structure RECT
Dim Left As Long
Dim top As Long
Dim right As Long
Dim bottom As Long
End Structure

Public FormActivateValue As Integer = 0
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong 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_CAPTION = &HC00000 ' WS_BORDER 或 WS_DLGFRAME
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000
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

Public Enum ESetWindowPosStyles
SWP_SHOWWINDOW = &H40
SWP_HIDEWINDOW = &H80
SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE
SWP_NOACTIVATE = &H10
SWP_NOCOPYBITS = &H100
SWP_NOMOVE = &H2
SWP_NOOWNERZORDER = &H200 ' Don't do owner Z ordering
SWP_NOREDRAW = &H8
SWP_NOREPOSITION = SWP_NOOWNERZORDER
SWP_NOSIZE = &H1
SWP_NOZORDER = &H4
SWP_DRAWFRAME = SWP_FRAMECHANGED
HWND_NOTOPMOST = -2
End Enum

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, ByVal lpRect As RECT) As Long

Private Function ShowTitleBar(ByVal bState As Boolean)
Dim lStyle As Long
Dim tR As RECT
' 获取窗口的位置:
GetWindowRect(Me.Handle.ToInt32, tR)
' 调整标题栏是否可见:
lStyle = GetWindowLong(Me.Handle.ToInt32, GWL_STYLE)
If (bState) Then
Me.Text = Me.Tag
If Me.ControlBox Then
lStyle = lStyle Or WS_SYSMENU
End If
If Me.MaximizeBox Then
lStyle = lStyle Or WS_MAXIMIZEBOX
End If
If Me.MinimizeBox Then
lStyle = lStyle Or WS_MINIMIZEBOX
End If
If Me.Text <> "" Then
lStyle = lStyle Or WS_CAPTION
End If
Else
Me.Tag = Me.Text
Me.Text = ""
lStyle = lStyle And Not WS_SYSMENU
lStyle = lStyle And Not WS_MAXIMIZEBOX
lStyle = lStyle And Not WS_MINIMIZEBOX
lStyle = lStyle And Not WS_CAPTION
End If
SetWindowLong(Me.Handle.ToInt32, GWL_STYLE, lStyle)
' 重新设定窗口:
SetWindowPos(Me.Handle.ToInt32, 0, tR.Left, tR.top, tR.right - tR.Left, tR.bottom - tR.top, &H200 Or &H4 Or &H20)
Me.Refresh()
' 你可能需要在Form_Resize中加一点代码,因为客户区的大小已经改变:
'Form_Resize
End Function

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧