【问题标题】:vb.net form and container sizing with "Change the size of all items" alteredvb.net 表单和容器大小与“更改所有项目的大小”已更改
【发布时间】:2015-11-01 11:27:26
【问题描述】:

我有一个在默认 100% 下运行良好的应用程序,但是如果用户将屏幕更改为 125% 或其他值,组容器的运行时大小和表单大小本身就会失败。我错过了什么?根据条件,组框会重新定位在表单上,​​并且会调整表单大小。我通过将我的系统重新设置为 125% 并调整控件和表单的运行时重新定位以匹配来确认这一点,然后它就起作用了。

【问题讨论】:

  • 看看这个关于应用程序中 dpi 的微软页面 ..msdn.microsoft.com/en-us/…
  • 看看这个question & answer
  • 该页面使用 VS2008,我使用的是 VS2013,在我的系统上没有看到引用的“HighDPIApp.sln”,在项目菜单中也没有“HandsOnLabProperties”选项,我错过了什么吗?

标签: vb.net forms screen


【解决方案1】:

这是我所做的,到目前为止它正在工作:

将 App.manifest 添加到项目中,并添加以下代码:

  <asmv1:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
    <dpiAware>true/PM</dpiAware>
  </asmv1:windowsSettings>

在我的启动表单中添加了以下子项:

Private Sub GetScreenDPI()

    Dim dspGraphics As Graphics

    dspGraphics = Me.CreateGraphics 'Graphics for user's display

    g_int_ScreenDPI = dspGraphics.DpiY

    Select Case g_int_ScreenDPI

        Case 96 'Smaller 100%

            g_dbl_screenDPI = 1

        Case 120 'Medium 125%

            g_dbl_screenDPI = 1.25

        Case 150 'Larger 150%

            g_dbl_screenDPI = 1.5

        Case Else 'Custom

            g_dbl_screenDPI = g_int_ScreenDPI / 100

    End Select

    dspGraphics.Dispose()

End Sub

以及我需要缩放控件或表单位置的地方:

Me.Height = CInt(550 * g_dbl_screenDPI)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    • 2016-09-01
    • 1970-01-01
    相关资源
    最近更新 更多