使Winforms全屏显示 [英] Making Winforms Fullscreen
本文介绍了使Winforms全屏显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使winform全屏显示.这是我在网上找到的.
I need to make a winform full screen. This is what i found online.
1. Hook WinProc to catch WM_SYSCOMMAND
2. Check wParam == SC_MAXIMIZE and then
3. Set my windiw's attributes
Me.ResizeMode = ResizeMode.NoResize
Me.WindowStyle = WindowStyle.None
Me.WindowState = WindowState.Maximized
我对vb.net还是很陌生,不知道该怎么做步骤1或2.有人可以给我一个片段,或向我指出正确的方向吗?
I am fairly new to vb.net and do not know how to do Steps 1 or 2. Can someone give me a snippet or point me in the right direction?
感谢giodamelio
Thanks giodamelio
推荐答案
诀窍是获取HwndSource并调用其AddHook()方法.这有效:
The trick is to obtain the HwndSource and call its AddHook() method. This works:
Imports System.Windows.Interop
Class Window1
Protected Overrides Sub OnSourceInitialized(ByVal e As System.EventArgs)
MyBase.OnSourceInitialized(e)
DirectCast(PresentationSource.FromVisual(Me), HwndSource).AddHook(AddressOf WndProc)
End Sub
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const SC_MAXIMIZE As Integer = &HF030
Private Function WndProc(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr, ByRef handled As Boolean) As IntPtr
If msg = WM_SYSCOMMAND AndAlso wp.ToInt32() = SC_MAXIMIZE Then
Me.ResizeMode = ResizeMode.NoResize
Me.WindowStyle = WindowStyle.None
Me.WindowState = WindowState.Maximized
handled = True
End If
End Function
End Class
Winforms表单的相同代码:
The same code for a Winforms Form:
Public Class Form1
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const SC_MAXIMIZE As Integer = &HF030
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32() = SC_MAXIMIZE Then
Me.FormBorderStyle = FormBorderStyle.None
Me.WindowState = FormWindowState.Maximized
Return
End If
MyBase.WndProc(m)
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
'' Restore window when the user presses Escape
If Me.WindowState = FormWindowState.Maximized AndAlso keyData = Keys.Escape Then
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
Me.WindowState = FormWindowState.Normal
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
End Class
这篇关于使Winforms全屏显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文