4

フォーラムを検索して、いくつか試してみましたが、うまくいきませんでした。私の問題を並べてみましょう。

ラップトップの画面解像度は非常に高く、1400x1050 です。私はこれで自分のアプリを設計しています。

私の同僚はラップトップ (解像度が低い) で試してみましたが、アプリケーションは彼のラップトップには収まりませんでした。ボタンが画面スペースから引きずり出されていました。

したがって、画面の解像度に基づいてアプリケーションのサイズを自動的に変更/調整したいと考えています。同様のフォーラムをいくつか見つけ、開発者が提案したことをいくつか試しましたが、うまくいきませんでした。

私は試しました: 解決策1 :しかし、フォームを調整する代わりに、ユーザーの画面解像度を変更しています。

画面の最大化オプションを使用したくないし、ユーザーの PC 設定を変更したくありません。残念ながら、私はテーブル レイアウト パネルを使用していません。

簡単な解決策を教えてください。

4

7 に答える 7

3

ばかげていることはわかっていますが... コントロールの「アンカー」を設定しようとしましたか?

フォームのサイズを変更するときにコントロールのサイズを変更できます。おそらく役立つかもしれません。スクロールバーの使用についても考えてください。

于 2011-01-20T15:50:32.560 に答える
3

わかりました、これはそれが得られるのと同じくらい簡単です。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

リフレクションを使用して、各コントロールに調整が必要なプロパティがあるかどうかを確認していることに注意してください。私がやっている方法はきれいですが、「遅延バインディング」を使用し、Option Strict Off が必要です。テストされ、承認されました。

于 2011-01-21T03:46:48.053 に答える
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)

これは、ほとんどのシナリオでうまくいくはずです (フォームがすでにサイズ変更を処理している限り)。あなたが望むものにはやり過ぎのように聞こえます。

于 2011-01-10T04:38:21.540 に答える
1

簡単な解決策?

スケールアップできるように、予想される最低の解像度 (EG 800x600) でアプリケーションを設計します。

于 2011-01-17T20:05:06.350 に答える
0

一部のコントロールを縮小できない、または縮小する意思がない場合は、ユーザーの意志で固定/表示/非表示できるある種のパネルを使用できる、または使用する意思があるかもしれません。これにより、柔軟性が向上します。

これらを見てください。

于 2011-01-17T20:02:25.863 に答える
0

vb.net 2013 このサイトでこのコードの一部を見つけましたが、クレジットを与えるために今すぐ見つけることができません!:-( 1780x760 の 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
于 2015-05-14T21:37:57.850 に答える