Windows Forms with High DPI


 





  1. Public Class Form1
  2.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3.         Tracer("Form1_Load")
  4.         StartTo_Write_Into_TextBox1 = True
  5.         AddHandler Application.Idle, AddressOf Application_Idle
  6.     End Sub
  7.     Public Sub New()
  8.         Application.EnableVisualStyles()
  9.         Tracer($"=========== New in ================")
  10.         ' 設計工具需要此呼叫。
  11.         InitializeComponent()
  12.         ' 在 InitializeComponent() 呼叫之後加入所有初始設定。
  13.         Me.TextBox1 = New System.Windows.Forms.TextBox()
  14.         Me.TextBox1.SuspendLayout()
  15.         Me.SuspendLayout()
  16.         Me.TextBox1.BackColor = System.Drawing.Color.LightSteelBlue
  17.         Me.TextBox1.ForeColor = System.Drawing.Color.Black
  18.         Me.TextBox1.Multiline = True
  19.         Me.TextBox1.ScrollBars = ScrollBars.Vertical
  20.         Me.TextBox1.Name = "TextBox1"
  21.         Me.TextBox1.TabIndex = 0
  22.         Me.TextBox1.Dock = System.Windows.Forms.DockStyle.Fill
  23.         Dim CX As Single = GetSystemMetricsForDpi(SM_CXSCREEN, DeviceDpi)
  24.         Dim CY As Single = GetSystemMetricsForDpi(SM_CYSCREEN, DeviceDpi)
  25.         OriginalDpi = DeviceDpi
  26.         Me.TextBox1.Font = Create_Font(initial_Font_Size)
  27.         Me.StartPosition = FormStartPosition.Manual
  28.         Me.Location = New Point(CInt(2), CInt(CY / 9))
  29.         Me.Size = New System.Drawing.Size(CInt(CX / 2), CInt(3 * CY / 5))
  30.         Me.Controls.Add(Me.TextBox1)
  31.         Me.ResumeLayout()
  32.         Me.TextBox1.ResumeLayout()
  33.         Tracer("============== New out =============")
  34.     End Sub

  35.     Private Sub Form1_HandleCreated(sender As Object, e As EventArgs) Handles Me.HandleCreated
  36.         Tracer("Form1_HandleCreated")
  37.         PreviousDpi = DeviceDpi
  38.         Dpi = DeviceDpi
  39.         Form1_Location = Me.Location
  40.         Form1_Size = Me.Size
  41.     End Sub
  42.     Sub Application_Idle(sender As Object, e As EventArgs)
  43.         RemoveHandler Application.Idle, AddressOf Application_Idle
  44.         Tracer("============= Application_Idle =================")
  45.         Dim StartInfo As New ProcessStartInfo("Rundll32.exe", "shell32,Control_RunDLL desk.cpl")
  46.         Process.Start(StartInfo)
  47.     End Sub

  48.     Private Sub Form1_HandleDestroyed(sender As Object, e As EventArgs) Handles Me.HandleDestroyed
  49.         Tracer("Form1_HandleDestroyed")
  50.         Show_TracedEvents_By_MSedge()
  51.     End Sub

  52.     Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
  53.         Tracer("Form1_Resize")
  54.     End Sub
  55.     Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged
  56.         Tracer("Form1_SizeChanged")
  57.         Form1_Size = Me.Size
  58.     End Sub
  59.     Private Sub Form1_Move(sender As Object, e As EventArgs) Handles Me.Move
  60.         Tracer("Form1_Move")
  61.     End Sub

  62.     Private Sub Form1_LocationChanged(sender As Object, e As EventArgs) Handles Me.LocationChanged
  63.         Tracer("Form1_LocationChanged")
  64.         Form1_Location = Me.Location
  65.     End Sub

  66.     Private Sub Form1_Layout(sender As Object, e As LayoutEventArgs) Handles Me.Layout
  67.         Tracer("Form1_Layout")
  68.         If Dpi <> PreviousDpi Then DpiChange()
  69.     End Sub
  70.     Protected Overrides Sub WndProc(ByRef m As Message)
  71.         Select Case m.Msg
  72.             Case WM_GETDPISCALEDSIZE
  73.                 PreviousDpi = Dpi
  74.                 Tracer($"WM_GETDPISCALEDSIZE-----------Dpi={m.WParam.ToInt32}")
  75.                 Dpi = m.WParam.ToInt32
  76.             Case WM_DPICHANGED
  77.                 Tracer($"WM_DPICHANGED----------Dpi={m.WParam.ToInt32 And &HFFFF}")
  78.                 'PreviousDpi = Dpi
  79.                 'Dpi = m.WParam.ToInt32 And &HFFFF
  80.             Case WM_DPICHANGED_BEFOREPARENT
  81.                 Tracer("WM_DPICHANGED_BEFOREPARENT------------------------")
  82.             Case WM_DPICHANGED_AFTERPARENT
  83.                 Tracer("WM_DPICHANGED_AFTERPARENT--------------------------")

  84.         End Select
  85.         MyBase.WndProc(m)
  86.     End Sub
  87.     Private Sub TextBox1_FontChanged(sender As Object, e As EventArgs) Handles TextBox1.FontChanged
  88.         Tracer("TextBox1_FontChanged")
  89.     End Sub
  90.     Private Sub TextBox1_Move(sender As Object, e As EventArgs) Handles TextBox1.Move
  91.         Tracer("TextBox1_Move")
  92.     End Sub
  93.     Private Sub TextBox1_LocationChanged(sender As Object, e As EventArgs) Handles TextBox1.LocationChanged
  94.         Tracer("TextBox1_LocationChanged")
  95.     End Sub
  96.     Private Sub TextBox1_Resize(sender As Object, e As EventArgs) Handles TextBox1.Resize
  97.         Tracer("TextBox1_Resize")
  98.     End Sub
  99.     Private Sub TextBox1_SizeChanged(sender As Object, e As EventArgs) Handles TextBox1.SizeChanged
  100.         Tracer("TextBox1_SizeChanged")

  101.     End Sub

  102.     Private Sub TextBox1_Layout(sender As Object, e As LayoutEventArgs) Handles TextBox1.Layout
  103.         Tracer("TextBox1_Layout")

  104.     End Sub
  105.     Private Sub Form1_StyleChanged(sender As Object, e As EventArgs) Handles Me.StyleChanged
  106.         Tracer("Form1_StyleChanged")
  107.     End Sub

  108.     Private Sub Form1_AutoSizeChanged(sender As Object, e As EventArgs) Handles Me.AutoSizeChanged
  109.         Tracer("Form1_AutoSizeChanged")
  110.     End Sub

  111.     Private Sub Form1_BindingContextChanged(sender As Object, e As EventArgs) Handles Me.BindingContextChanged
  112.         Tracer("Form1_BindingContextChanged")
  113.     End Sub

  114.     Private Sub Form1_ChangeUICues(sender As Object, e As UICuesEventArgs) Handles Me.ChangeUICues
  115.         Tracer("Form1_ChangeUICues")
  116.     End Sub
  117.     Private Sub Form1_Activated(sender As Object, e As EventArgs) Handles Me.Activated
  118.         Tracer("Form1_Activated")
  119.     End Sub
  120.     Private Sub Form1_Deactivate(sender As Object, e As EventArgs) Handles Me.Deactivate
  121.         Tracer("Form1_Deactivate")
  122.     End Sub
  123.     Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles Me.Closed
  124.         Tracer("Form1_Closed")
  125.     End Sub

  126.     Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
  127.         Tracer("Form1_FormClosed")
  128.     End Sub
  129.     Private Sub Form1_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles Me.Closing
  130.         Tracer("Form1_Closing")
  131.     End Sub

  132.     Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
  133.         Tracer("Form1_FormClosing")
  134.     End Sub

  135.     Private Sub TextBox1_Enter(sender As Object, e As EventArgs) Handles TextBox1.Enter
  136.         Tracer("TextBox1_Enter")
  137.     End Sub

  138.     Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
  139.         Tracer("TextBox1_Leave")
  140.     End Sub

  141.     Private Sub Form1_MarginChanged(sender As Object, e As EventArgs) Handles Me.MarginChanged
  142.         Tracer("Form1_MarginChanged")
  143.     End Sub

  144.     Private Sub Form1_PaddingChanged(sender As Object, e As EventArgs) Handles Me.PaddingChanged
  145.         Tracer("Form1_PaddingChanged")
  146.     End Sub
  147.     Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  148.         Static FourTimes As Int32 = 4
  149.         If FourTimes = 0 Then Exit Sub
  150.         FourTimes -= 1
  151.         Tracer($"Form1_Paint ({FourTimes})")
  152.     End Sub

  153.     Private Sub Form1_Validated(sender As Object, e As EventArgs) Handles Me.Validated
  154.         Tracer("Form1_Validated")
  155.     End Sub
  156.     Private Sub Form1_CausesValidationChanged(sender As Object, e As EventArgs) Handles Me.CausesValidationChanged
  157.         Tracer("Form1_CausesValidationChanged")
  158.     End Sub

  159.     Private Sub Form1_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged
  160.         Tracer("Form1_VisibleChanged")
  161.     End Sub
  162.     Private Sub Form1_LostFocus(sender As Object, e As EventArgs) Handles Me.LostFocus
  163.         Tracer("Form1_LostFocus")
  164.     End Sub
  165.     Private Sub Form1_DpiChanged(sender As Object, e As DpiChangedEventArgs) Handles Me.DpiChanged
  166.         Tracer($"Form1_DpiChanged---->NewDpi={e.DeviceDpiNew} oldDpi={e.DeviceDpiOld} ")
  167.     End Sub
  168.     Private Sub Form1_DpiChangedAfterParent(sender As Object, e As EventArgs) Handles Me.DpiChangedAfterParent
  169.         Tracer("Form1_DpiChangedAfterParent-----------------")
  170.     End Sub

  171.     Private Sub Form1_DpiChangedBeforeParent(sender As Object, e As EventArgs) Handles Me.DpiChangedBeforeParent
  172.         Tracer("Form1_DpiChangedBeforeParent------------------")
  173.     End Sub
  174.     Private Sub Form1_DragDrop(sender As Object, e As DragEventArgs) Handles Me.DragDrop
  175.         Tracer("Form1_DragDrop")
  176.     End Sub
  177.     Private Sub Form1_SystemColorsChanged(sender As Object, e As EventArgs) Handles Me.SystemColorsChanged
  178.         Tracer("Form1_SystemColorsChanged")
  179.     End Sub
  180.     Private Sub Form1_TabIndexChanged(sender As Object, e As EventArgs) Handles Me.TabIndexChanged
  181.         Tracer("Form1_TabIndexChanged")
  182.     End Sub
  183.     Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
  184.         Tracer("Form1_Shown")
  185.     End Sub
  186.     Private Sub Form1_TextChanged(sender As Object, e As EventArgs) Handles Me.TextChanged
  187.         Tracer("Form1_TextChanged")
  188.     End Sub
  189.     Private Sub Form1_QueryContinueDrag(sender As Object, e As QueryContinueDragEventArgs) Handles Me.QueryContinueDrag
  190.         Tracer("Form1_QueryContinueDrag")
  191.     End Sub
  192.     Private Sub Form1_ResizeBegin(sender As Object, e As EventArgs) Handles Me.ResizeBegin
  193.         Tracer("Form1_ResizeBegin")
  194.     End Sub
  195.     Private Sub Form1_Enter(sender As Object, e As EventArgs) Handles Me.Enter
  196.         Tracer("Form1_Enter")
  197.     End Sub
  198.     Private Sub Form1_Leave(sender As Object, e As EventArgs) Handles Me.Leave
  199.         Tracer("Form1_Leave")
  200.     End Sub
  201.     Private Sub Form1_Scroll(sender As Object, e As ScrollEventArgs) Handles Me.Scroll
  202.         Tracer("Form1_Scroll")
  203.     End Sub
  204.     Private Sub Form1_RegionChanged(sender As Object, e As EventArgs) Handles Me.RegionChanged
  205.         Tracer("Form1_RegionChanged")
  206.     End Sub
  207.     Private Sub Form1_MdiChildActivate(sender As Object, e As EventArgs) Handles Me.MdiChildActivate
  208.         Tracer("Form1_MdiChildActivate")
  209.     End Sub
  210.     Private Sub Form1_RightToLeftLayoutChanged(sender As Object, e As EventArgs) Handles Me.RightToLeftLayoutChanged
  211.         Tracer("Form1_RightToLeftLayoutChanged")
  212.     End Sub
  213.     Private Sub Form1_BackColorChanged(sender As Object, e As EventArgs) Handles Me.BackColorChanged
  214.         Tracer("Form1_BackColorChanged")
  215.     End Sub
  216.     Private Sub Form1_Click(sender As Object, e As EventArgs) Handles Me.Click
  217.         Tracer("Form1_Click")
  218.     End Sub
  219.     Private Sub Form1_ControlAdded(sender As Object, e As ControlEventArgs) Handles Me.ControlAdded
  220.         Tracer("Form1_ControlAdded")
  221.     End Sub

  222.     Private Sub Form1_ControlRemoved(sender As Object, e As ControlEventArgs) Handles Me.ControlRemoved
  223.         Tracer("Form1_ControlRemoved")
  224.     End Sub
  225.     Private Sub Form1_GotFocus(sender As Object, e As EventArgs) Handles Me.GotFocus
  226.         Tracer("Form1_GotFocus")
  227.     End Sub
  228.     Private Sub Form1_FontChanged(sender As Object, e As EventArgs) Handles Me.FontChanged
  229.         Tracer("Form1_FontChanged")
  230.     End Sub
  231.     Private Sub Form1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles Me.Validating
  232.         Tracer("Form1_Validating")
  233.     End Sub

  234.     Private Sub Form1_Invalidated(sender As Object, e As InvalidateEventArgs) Handles Me.Invalidated
  235.         Tracer("Form1_Invalidated")
  236.     End Sub

  237.     Private Sub Form1_TabStopChanged(sender As Object, e As EventArgs) Handles Me.TabStopChanged
  238.         Tracer("Form1_TabStopChanged")
  239.     End Sub

  240.     Private Sub Form1_RightToLeftChanged(sender As Object, e As EventArgs) Handles Me.RightToLeftChanged
  241.         Tracer("Form1_RightToLeftChanged")
  242.     End Sub
  243.     Private Sub Form1_DockChanged(sender As Object, e As EventArgs) Handles Me.DockChanged
  244.         Tracer("Form1_DockChanged")
  245.     End Sub
  246. #If TRACE Then
  247. #Region "Mouse event"
  248.     Private Sub Form1_MouseCaptureChanged(sender As Object, e As EventArgs) Handles Me.MouseCaptureChanged
  249.         Tracer("Form1_MouseCaptureChanged")
  250.     End Sub

  251.     Private Sub Form1_MouseEnter(sender As Object, e As EventArgs) Handles Me.MouseEnter
  252.         Tracer("Form1_MouseEnter")
  253.     End Sub
  254.     Private Sub Form1_MouseLeave(sender As Object, e As EventArgs) Handles Me.MouseLeave
  255.         Tracer("Form1_MouseLeave")
  256.     End Sub
  257.     Private Sub Form1_MouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel
  258.         Tracer("Form1_MouseWheel")
  259.     End Sub

  260.     Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
  261.         Tracer("Form1_MouseClick")
  262.     End Sub

  263.     Private Sub TextBox1_MouseEnter(sender As Object, e As EventArgs) Handles TextBox1.MouseEnter
  264.         Tracer("TextBox1_MouseEnter")
  265.     End Sub
  266.     Private Sub TextBox1_MouseLeave(sender As Object, e As EventArgs) Handles TextBox1.MouseLeave
  267.         Tracer("TextBox1_MouseLeave")
  268.     End Sub
  269.     Private Sub TextBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseUp
  270.         Tracer("TextBox1_MouseUp")
  271.     End Sub
  272.     Private Sub TextBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseDown
  273.         Tracer("TextBox1_MouseDown")
  274.     End Sub
  275.     Private Sub TextBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseClick
  276.         Tracer("TextBox1_MouseClick")
  277.     End Sub
  278.     Private Sub TextBox1_MouseHover(sender As Object, e As EventArgs) Handles TextBox1.MouseHover
  279.         Static ThreeTimes As Int32 = 3
  280.         If ThreeTimes = 0 Then Exit Sub
  281.         ThreeTimes -= 1
  282.         Tracer($"TextBox1_MouseHover({ThreeTimes})")
  283.     End Sub
  284.     Private Sub Form1_MouseHover(sender As Object, e As EventArgs) Handles Me.MouseHover
  285.         Tracer("Form1_MouseHover")
  286.     End Sub

  287. #End Region
  288. #Region "No use"

  289.     Private Sub Form1_MenuComplete(sender As Object, e As EventArgs) Handles Me.MenuComplete
  290.         Tracer("Form1_MenuComplete")
  291.     End Sub
  292.     Private Sub Form1_MenuStart(sender As Object, e As EventArgs) Handles Me.MenuStart
  293.         Tracer("Form1_MenuStart")
  294.     End Sub
  295.     Private Sub Form1_GiveFeedback(sender As Object, e As GiveFeedbackEventArgs) Handles Me.GiveFeedback
  296.         Tracer("Form1_GiveFeedback")

  297.     End Sub
  298.     Private Sub Form1_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
  299.         Tracer("Form1_ResizeEnd")
  300.     End Sub
  301.     Private Sub Form1_ImeModeChanged(sender As Object, e As EventArgs) Handles Me.ImeModeChanged
  302.         Tracer("Form1_ImeModeChanged")
  303.     End Sub
  304.     Private Sub TextBox1_RegionChanged(sender As Object, e As EventArgs) Handles TextBox1.RegionChanged
  305.         Tracer("TextBox1_RegionChanged")
  306.     End Sub

  307. #End Region
  308. #End If
  309.     Friend WithEvents TextBox1 As TextBox
  310. End Class
  311. Module MyModule1
  312.     Public Dpi, PreviousDpi, OriginalDpi As Single
  313.     Public Const initial_Font_Size = 12.0!
  314.     Public Form1_Location As Point
  315.     Public Form1_Size As Size
  316.     Class CreateOneObject
  317.         Sub New(ByRef Event_Traces2 As Text.StringBuilder)
  318.             Event_Traces2 = New Text.StringBuilder
  319.         End Sub
  320.     End Class
  321.     Public Event_Traces As Text.StringBuilder
  322.     Public StartTo_Write_Into_TextBox1 As Boolean
  323.     Sub Tracer(str2 As String)
  324.         Static RunOnlyOnce As New CreateOneObject(Event_Traces)
  325.         Event_Traces.AppendLine(str2)
  326.         If StartTo_Write_Into_TextBox1 Then
  327.             If Form1.TextBox1.TextLength = 0 Then
  328.                 Form1.TextBox1.Text = Event_Traces.ToString
  329.             Else
  330.                 Form1.TextBox1.AppendText(str2 & vbNewLine)
  331.             End If
  332.         End If
  333.     End Sub
  334.     Sub DpiChange()
  335.         Try
  336.             Dim Font_Scaling As Single = Dpi / OriginalDpi
  337.             Form1.TextBox1.Font.Dispose()
  338.             Form1.TextBox1.Font = Create_Font(initial_Font_Size * Font_Scaling)

  339.             Dim Pos_Scaling As Single = Dpi / PreviousDpi
  340.             SetWindowPos(Form1.Handle, Form1.Handle,
  341.                              CInt(Form1_Location.X * Pos_Scaling),
  342.                              CInt(Form1_Location.Y * Pos_Scaling),
  343.                              CInt(Form1_Size.Width * Pos_Scaling),
  344.                              CInt(Form1_Size.Height * Pos_Scaling),
  345.                              SWP_NOACTIVATE Or SWP_NOZORDER)
  346.             PreviousDpi = Dpi
  347.         Catch ex As Exception
  348.             MsgBox($"DpiChange error {ex.Message}")
  349.         End Try

  350.     End Sub

  351.     Public ReadOnly FontFamilyNames() As String = {
  352.           "SimSun", "MingLiU", "Courier New", "Cascadia Mono"}
  353.     Function Create_Font(fontsize As Single) As Font
  354.         For Each name As String In FontFamilyNames
  355.             Try
  356.                 Dim [FontFamily] As FontFamily
  357.                 [FontFamily] = New Drawing.FontFamily(name)
  358.                 If [FontFamily] IsNot Nothing Then
  359.                     Return New Drawing.Font([FontFamily], fontsize,
  360.                         FontStyle.Regular, GraphicsUnit.Point, CType(0, Byte))
  361.                 End If
  362.             Catch ex As Exception
  363.             End Try
  364.         Next
  365.         Throw New Exception("Font not found ---cheninnjer")
  366.     End Function
  367.     Sub Show_TracedEvents_By_MSedge()
  368.         Dim HtmlFilePath As String = IO.Path.Combine(IO.Path.GetTempPath, "Trace.html")
  369.         Using HtmlFile As New IO.StreamWriter(HtmlFilePath)
  370.             Event_Traces.Replace(vbNewLine, $"</li>{vbNewLine}<li>").Insert(0, "<li>").Length -= 4
  371.             HtmlFile.Write(
  372.         $"<!DocType html>
  373.           <html>
  374.              <head>
  375.                    <title> Event tracers </title>
  376.                    <style> 
  377.                         ol {{
  378.                                    color:black;
  379.                                    font-size:large; 
  380.                                    background-color:yellow;
  381.                                    font-weight:600;
  382.                            }}
  383.                     </style>
  384.              </head>
  385.              <body>
  386.                     <h2> List of event traces</h2> 
  387.                    <ol>
  388.                      {Event_Traces}
  389.                    </ol>
  390.              </body>
  391.           </html>")
  392.         End Using
  393.         Dim StartInfo As New ProcessStartInfo("msedge.exe", HtmlFilePath) With {.Verb = "open",
  394.             .WorkingDirectory = IO.Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles(x86)"),
  395.               "\Microsoft\Edge\Application"), .UseShellExecute = True}
  396.         Process.Start(StartInfo)
  397.     End Sub
  398.     Declare Unicode Function GetSystemMetricsForDpi Lib "User32" (
  399.            _In_int_nIndex As Int32,
  400.            _In_UINT_dpi As Int32) As Int32
  401.     Declare Unicode Function SetWindowPos Lib "User32" (
  402.             _In_HWND_hWnd As IntPtr,
  403.             _In_opt_HWND_hWndInsertAfter As IntPtr,
  404.             _In_int_X As Int32,
  405.             _In_int_Y As Int32,
  406.             _In_int_cx As Int32,
  407.             _In_int_cy As Int32,
  408.             _In_UINT_uFlags As UInt32) As Boolean
  409.     Public Const SM_CXSCREEN As Int32 = 0
  410.     Public Const SM_CYSCREEN As Int32 = 1
  411.     Public Const WM_DPICHANGED As UInt32 = &H2E0
  412.     Public Const WM_DPICHANGED_BEFOREPARENT As UInt32 = &H2E2
  413.     Public Const WM_DPICHANGED_AFTERPARENT As UInt32 = &H2E3
  414.     Public Const WM_GETDPISCALEDSIZE As UInt32 = &H2E4

  415.     Public Const SWP_NOSIZE As UInt32 = &H1
  416.     Public Const SWP_NOMOVE As UInt32 = &H2
  417.     Public Const SWP_NOZORDER As UInt32 = &H4
  418.     Public Const SWP_NOREDRAW As UInt32 = &H8
  419.     Public Const SWP_NOACTIVATE As UInt32 = &H10
  420.     Public Const SWP_FRAMECHANGED As UInt32 = &H20   '/* The frame changed: send WM_NCCALCSIZE */
  421.     Public Const SWP_SHOWWINDOW As UInt32 = &H40
  422.     Public Const SWP_HIDEWINDOW As UInt32 = &H80
  423.     Public Const SWP_NOCOPYBITS As UInt32 = &H100
  424.     Public Const SWP_NOOWNERZORDER As UInt32 = &H200   '/* Don't do owner Z ordering */
  425.     Public Const SWP_NOSENDCHANGING As UInt32 = &H400   '/* Don't send WM_WINDOWPOSCHANGING */
  426.     Public Const SWP_DEFERERASE As UInt32 = &H2000
  427.     Public Const SWP_ASYNCWINDOWPOS As UInt32 = &H4000
  428.     Public Const SWP_DRAWFRAME As UInt32 = SWP_FRAMECHANGED
  429.     Public Const SWP_NOREPOSITION As UInt32 = SWP_NOOWNERZORDER
  430. End Module



  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.     <startup>
  4.         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  5.     </startup>
  6. <System.Windows.Forms.ApplicationConfigurationSection>
  7. <add key="DpiAwareness" value="PerMonitorV2" />
  8. </System.Windows.Forms.ApplicationConfigurationSection>
  9. </configuration>






Reference:High DPI support in Windows Forms


留言

這個網誌中的熱門文章

Marshalling

Calling a C# WPF library from C++

Marshalling II