VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,793 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi
Using this code to switch to dark and light mode for my .Net Framework 4.8 app only, but they won't apply until the form is resized, I can do:
Me.Width = Me.Width + 1
Me.Width = Me.Width - 1
But that's not the way to go, the code, Windows 10 21H2, any help is appreciated :)
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("dwmapi.dll", CharSet:=CharSet.Unicode, PreserveSig:=True)>
Public Shared Function DwmSetWindowAttribute(hwnd As IntPtr, attr As Integer, ByRef attrValue As Boolean, attrSize As Integer) As Integer
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DwmSetWindowAttribute(Me.Handle, 20, False, Runtime.InteropServices.Marshal.SizeOf(True))
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
DwmSetWindowAttribute(Me.Handle, 20, True, Runtime.InteropServices.Marshal.SizeOf(True))
End Sub
End Class
A way is to force activation of caption, like :
SendMessage(Me.Handle, WM_NCACTIVATE, CType(False, IntPtr), IntPtr.Zero)
SendMessage(Me.Handle, WM_NCACTIVATE, CType(True, IntPtr), IntPtr.Zero)
with :
<DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As IntPtr, lParam As IntPtr) As Integer
End Function
Public Const WM_NCACTIVATE = &H86