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