2015-11-01 69 views
0

我有一个应用程序,在默认的100%很好,但是,如果用户已将屏幕更改为125%或其他运行时调整大小组容器和表单大小本身失败。我错过了什么?根据条件,组框将重新放置在表单上,​​并调整表单的大小。我确认了这一点,将我的系统重新设置为125%,然后调整控件的运行时重新定位和窗体匹配,然后运行。vb.net窗体和容器大小与“更改所有项目的大小”更改

+0

查看此应用程序中有关dpi的微软页面。https://msdn.microsoft.com/en-us/windows7trainingcourse_win7highdpinative_topic1 –

+0

看看这个[问答](http://stackoverflow.com/questions/23101791/make-vb-net-application-dpi-aware)。 – theB

+0

该页面使用VS2008,我使用VS2013,并没有看到我的系统上引用的“HighDPIApp.sln”,也没有在项目菜单中有“HandsOnLabProperties”的选项,我错过了什么吗? – Terabithia

回答

0

这里是我做了什么,以及它是工作迄今:

新增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)