gpt4 book ai didi

vb.net - 使 Winforms 全屏显示

转载 作者:行者123 更新时间:2023-12-02 04:39:01 26 4
gpt4 key购买 nike

我需要制作一个winform全屏。这是我在网上找到的。

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。有人能给我一个片段或指出正确的方向吗?

谢谢乔达梅里奥

最佳答案

诀窍是获取 HwndSource 并调用其 AddHook() 方法。这有效:

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 表单的相同代码:

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

关于vb.net - 使 Winforms 全屏显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4649877/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com