2011-01-10 132 views
4

我在论坛上搜索,我尝试了几件事......但他们似乎并没有工作。让我解决我的问题。根据屏幕分辨率更改屏幕分辨率(不改变显示器分辨率并使用最大化屏幕选项)

我的笔记本电脑屏幕分辨率非常高:1400x1050。我正在设计我的应用程序。

我的同事在他的笔记本电脑(分辨率较低)上尝试过,而且该应用程序不适合他的笔记本电脑。按钮拖出屏幕空间。

所以,我希望我的应用程序根据屏幕分辨率自动调整大小/调整。 我发现了一些类似的论坛,我尝试了一些开发人员提出的建议,但那并不适合我。

我试过了: Solution 1:但正在改变用户的屏幕取代调整表单。

我不想使用Maximized屏幕选项,也不想更改用户的电脑设置。 不幸的是我没有使用表格布局面板。

请给我一个简单的解决方案。

+0

您可以添加表格的截图。我要看看你能不能伸展任何控件。有些选项可以根据字体大小等来缩放表单,但这取决于你想要的最终效果。 – ja72 2011-01-10 04:36:23

+0

我不能在这里放置屏幕截图。但是可以打开一些表单详细信息:表单大小:1130,863,开始位置:CenterScreen和Window State:Normal(包含近80个UI组件)。 – Preeti 2011-01-10 04:51:24

+0

您是否已将`AutoScaleMode`属性设置为`Dpi`? http://msdn.microsoft.com/en-us/library/system.windows.forms.autoscalemode.aspx – 2011-01-17 18:59:34

回答

1

您可以使用下面的代码来获取主屏幕的高度和宽度:鉴于这一点,你应该进行检查

Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width 
Dim intY As Integer = Screen.PrimaryScreen.Bounds.Height 

加载窗体时,确保你的表格宽度大于屏幕宽度:

// This is pseudocode, as I usually do C#: 
MyForm.Width = Min(ScreenWidth, MyForm.Width) 
MyForm.Height = Min(ScreenHeight, MyForm.Height) 

这应该做(只要已经处理了被调整的形式),在大多数情况下的伎俩 - 如果要满足多个屏幕,然后将需要一些额外的逻辑来得到屏幕的尺寸你的表单开始,但这听起来像是你想要的矫枉过正。

0

如果您无法或不愿意缩小某些控件,您可能或愿意使用某种可以在用户意愿下固定/显示/隐藏的面板。这会给你更多的灵活性。

Have a look at these.

1

简单的解决方案?

以最低预期分辨率(E.G. 800x600)设计您的应用程序,以便可以放大应用程序。

2

我知道这很愚蠢,但是......你是否试图设置控制“锚”

它们可以让你的控制,当你调整你的形式,也许可以帮你调整,也考虑使用滚动条

2

OK,这只是因为它得到一样简单。只需遍历VB控件并根据新屏幕分辨率与设计屏幕分辨率的比率调整其大小。即类似的东西:

Dim DesignScreenWidth As Integer = 1600 
    Dim DesignScreenHeight As Integer = 1200 
    Dim CurrentScreenWidth As Integer = Screen.PrimaryScreen.Bounds.Width 
    Dim CurrentScreenHeight As Integer = Screen.PrimaryScreen.Bounds.Height 
    Dim RatioX as Double = CurrentScreenWidth/DesignScreenWidth 
    Dim RatioY as Double = CurrentScreenHeight/DesignScreenHeight 
    For Each iControl In Me.Controls 
     With iControl 
      If (.GetType.GetProperty("Width").CanRead) Then .Width = CInt(.Width * RatioX) 
      If (.GetType.GetProperty("Height").CanRead) Then .Height = CInt(.Height * RatioY) 
      If (.GetType.GetProperty("Top").CanRead) Then .Top = CInt(.Top * RatioX) 
      If (.GetType.GetProperty("Left").CanRead) Then .Left = CInt(.Left * RatioY) 
     End With 
    Next 

请注意,我正在使用反射来查看每个控件是否具有我们需要调整的属性。我这样做的方式很干净,但使用“后期绑定”,并要求选项严格关闭。经过测试和批准。

0

vb.net 2013在这个网站上发现了一些这样的代码,现在找不到它来给予功劳!:-(在17.5x760的15.5笔记本电脑上制作,改变用户主屏幕的工作区域。形式新的大小,太多,如果它击中了原来的某个资源的字体。试试吧,用它玩。

Option Strict On 
Option Explicit On 
Public Class Form1 
    ' For screen size changes. 
    Dim cw As Integer ' Forms current Width. 
    Dim ch As Integer ' Forms current Height. 
    Dim iw As Integer = 1280 ' Forms initial width. 
    Dim ih As Integer = 760 ' Forms initial height. 
    ' Retrieve the working rectangle from the Screen class using the  PrimaryScreen and the WorkingArea properties. 
    Dim workingRectangle As System.Drawing.Rectangle =  Screen.PrimaryScreen.WorkingArea 

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    ' Set the size of the form slightly less than size of working rectangle. 
    Me.Size = New System.Drawing.Size(workingRectangle.Width - 5, workingRectangle.Height - 5) 
    ' Set the location so the entire form is visible. 
    Me.Location = New System.Drawing.Point(3, 3) 
End Sub 

Private Sub Main_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize 
    ' Change controls size and fonts to fit screen working area.. 
    Dim rw As Double = (Me.Width - cw)/cw ' Ratio change of original form width. 
    Dim rh As Double = (Me.Height - ch)/ch ' Ratio change of original form height. 
    ' Change controls size to fit users screen working area. 
    For Each Ctrl As Control In Controls 
     Ctrl.Width += CInt(Ctrl.Width * rw) 
     Ctrl.Height += CInt(Ctrl.Height * rh) 
     Ctrl.Left += CInt(Ctrl.Left * rw) 
     Ctrl.Top += CInt(Ctrl.Top * rh) 
    Next 
    cw = Me.Width 
    ch = Me.Height 
    ' Change all the forms controls font size. 
    Dim nfsize As Single 
    If cw > iw + 500 Then 
     For Each Ctrl As Control In Controls 
      ' Get the forms controls font size's property and increase it. Reset the font to the new size. 
      nfsize = Me.Font.Size + 3 
      Ctrl.Font = New Font(Ctrl.Font.Name, nfsize, FontStyle.Bold, Ctrl.Font.Unit) 
     Next 
    Else 
     Exit Sub 
    End If 
End Sub