求C#无边框窗体最大化后不档住任务栏的解决办法

littlelam --  2008-10-16 11:18:06

Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib ""user32"" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function FindWindow Lib ""user32"" Alias ""FindWindowA"" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib ""user32"" Alias ""FindWindowExA"" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetDesktopWindow Lib ""user32"" () As Long

Private Sub Command1_Click()
Me.WindowState = 2
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim hTaskBar As Long
hTaskBar = FindWindow(""Shell_TrayWnd"", vbNullString)
Debug.Print hTaskBar
Dim RC As RECT
Dim i As Long
i = GetWindowRect(hTaskBar, RC)
Dim taskheight As Long
taskheight = RC.Bottom - RC.Top '任务栏高度
i = GetWindowRect(GetDesktopWindow, RC)
Dim maxwidth As Long
Dim maxheight As Long
maxwidth = RC.Right - RC.Left '获取屏幕宽度
maxheight = RC.Bottom - RC.Top - taskheight '屏幕高度-任务栏高度
LockWindow Me.hwnd, , , maxwidth, maxheight
End Sub

模块代码:
Option Explicit

Public Type POINTAPI
x As Long
y As Long
End Type

Public Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type

Public Declare Sub CopyMemory Lib ""kernel32"" Alias ""RtlMoveMemory"" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function CallWindowProc Lib ""user32"" Alias ""CallWindowProcA"" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Declare Function SetWindowLong Lib ""user32"" Alias ""SetWindowLongA"" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SendMessage Lib ""user32"" Alias ""SendMessageA"" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_GETMINMAXINFO = &H24
Public Const GWL_WNDPROC = -4

Global lpPrevWndProc As Long
Public procOld As Long
Public udtMMI As MINMAXINFO

Public Function WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_GETMINMAXINFO
Dim udtMINMAXINFO As MINMAXINFO
CopyMemory udtMINMAXINFO, ByVal lParam, 40&
With udtMINMAXINFO
.ptMaxSize.x = udtMMI.ptMaxSize.x
.ptMaxSize.y = udtMMI.ptMaxSize.y
.ptMaxPosition.x = 0
.ptMaxPosition.y = 0
.ptMaxTrackSize.x = .ptMaxSize.x
.ptMaxTrackSize.y = .ptMaxSize.y
.ptMinTrackSize.x = udtMMI.ptMinTrackSize.x
.ptMinTrackSize.y = udtMMI.ptMinTrackSize.y
Debug.Print .ptMaxSize.x & "","" & .ptMaxSize.y
End With
CopyMemory ByVal lParam, udtMINMAXINFO, 40&
WindowProc = False
Exit Function
End Select
WindowProc = CallWindowProc(procOld, hwnd, iMsg, wParam, lParam)
End Function

Public Function LockWindow(hwnd As Long, Optional MinWidth As Long, Optional MinHeight As Long, Optional maxwidth As Long, Optional maxheight As Long) As Boolean
With udtMMI
'指定窗体最小宽度
If MinWidth = 0 Then .ptMinTrackSize.x = 0 Else .ptMinTrackSize.x = MinWidth
'指定窗体最小高度
If MinHeight = 0 Then .ptMinTrackSize.y = 0 Else .ptMinTrackSize.y = MinHeight
'指定窗体最大宽度
If maxwidth = 0 Then .ptMaxSize.x = Screen.Width \ Screen.TwipsPerPixelX Else .ptMaxSize.x = maxwidth
'指定窗体最大高度
If maxheight = 0 Then .ptMaxSize.y = Screen.Width \ Screen.TwipsPerPixelX Else .ptMaxSize.y = maxheight
End With
procOld = SetWindowLong(hwnd, -4, AddressOf WindowProc)
End Function

上面一个是VB.NET的
求C#无边框窗体最大化后不档住任务栏的解决办法
...全文
1006 点赞 收藏 16
写回复
16 条回复
Ericly 2012年08月31日
[Quote=引用 15 楼 的回复:]

Me.MaximizeBox = False
Me.MaximizedBounds = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea
[/Quote]


可以在窗体组件初始化完后,加入
this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;

this.Size = Screen.PrimaryScreen.WorkingArea.Size;
回复 点赞
niulei 2011年04月21日
Me.MaximizeBox = False
Me.MaximizedBounds = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea
回复 点赞
miss987 2009年07月22日
得分回复需要阅读
回复 点赞
wangyanboq 2008年10月16日
还有一种方法是在form的form.designer.vb中设置
me.MaxinumSize = new System.Drawing.Size(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height)
回复 点赞
littlelam 2008年10月16日
原来能设置。。。。
MaximizedBounds
回复 点赞
shangwei97 2008年10月16日
关注,应该不会太难吧,
我做windows mobile 的全屏
回复 点赞
wangyanboq 2008年10月16日
ME.MaximizedBounds=System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
回复 点赞
CloneCenter 2008年10月16日
无边框的窗体,你如何最大化?用代码?用户肯定是没有办法操作的。

所以这里就不要想什么最大化了,修改一下窗体的 Size 即可!Top和Left属性设置为-1,Width和Height设置为Screen.WorkingArea.Width + 2和 Height + 2。试试看……
回复 点赞
liujb526 2008年10月16日
呵呵,帮顶顺便学习
回复 点赞
ZengHD 2008年10月16日
晕,标题有歧义啊

回复 点赞
littlelam 2008年10月16日
[Quote=引用 1 楼 cpio 的回复:]
主要是最大化后,把窗口置前
[/Quote]
我不是要最前,是不要 档住任务栏
和普通窗口最大化一样的效果,也就是不要全屏
回复 点赞
wangxiao2008 2008年10月16日
学习一下
回复 点赞
ZengHD 2008年10月16日
[Quote=引用 2 楼 cpio 的回复:]

新建一个窗口,放一个button,就两行代码就可以的,你试试看
private void button1_Click(object sender, EventArgs e)
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
}
[/Quote]
呵呵,我也想到这个方法了

回复 点赞
cpio 2008年10月16日
要是还不放心,可以置顶


FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;

TopMost = true;//置顶
回复 点赞
cpio 2008年10月16日

新建一个窗口,放一个button,就两行代码就可以的,你试试看
private void button1_Click(object sender, EventArgs e)
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
}
回复 点赞
cpio 2008年10月16日
主要是最大化后,把窗口置前

回复 点赞
发动态
发帖子
C#
创建于2007-09-28

8.4w+

社区成员

64.0w+

社区内容

.NET技术 C#
社区公告
暂无公告