2015-11-01 70 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)