HI Claude
Have you considered the users choice in windows/settings/system/display. Whether the user choices 100%, 125% or whatever. The point is you need to use methods in the size and layout of all your forms, dialogs, and controls, and fonts on your user interfaces. WPF make this all easier, but if your are like myself a stickler for windows.forms, you need to take care of all those details yourself in code - usually the load event, the resize event, or maximise events.
Use {My.Computer.Screen.WorkingArea.Width} (and .Height) to see how much room you've got to play with.
If the user changes their windows display setting, this will be reflected in the pixel width/height that is returned.
Here is a simplified example of variable form sizing resulting in fonts and controls being resized correctly.
Public Class Form5 ' Example regarding resizing forms and control bounds
Dim isMax, isEvntSus As Boolean
Dim fW, fH As Integer
Dim strFntName As String
Dim fnt As Font
Dim reScale As Double
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim I, J, K As Integer
I = My.Settings.FrmSz.IndexOf(",")
fW = CInt(My.Settings.FrmSz.Substring(0, I))
fH = CInt(My.Settings.FrmSz.Substring(I + 1, My.Settings.FrmSz.Length - I - 1))
isEvntSus = True
ClientSize = New Size(fW, fH)
isEvntSus = False
I = Screen.PrimaryScreen.WorkingArea.Width - Width + fW
J = Screen.PrimaryScreen.WorkingArea.Height - Height + fH
If (fW / fH) > (I / J) Then ' screen width will detirmine
K = CInt(I * 0.75) + Height - fH
MaximizedBounds = New Rectangle(0, CInt((Screen.PrimaryScreen.WorkingArea.Height - K) / 2), _
Screen.PrimaryScreen.WorkingArea.Width, K)
Else ' screen height will detirmine
K = CInt(J / 0.75) + Width - fW
MaximizedBounds = New Rectangle(CInt((Screen.PrimaryScreen.WorkingArea.Width - K) / 2), _
0, K, Screen.PrimaryScreen.WorkingArea.Height)
End If
MinimumSize = New Size(400 + Width - fW, 300 + Height - fH)
MaximumSize = MaximizedBounds.Size
strFntName = "microsoft sans serif"
For Each FF As FontFamily In FontFamily.Families
If FF.Name.ToLower = "segoe ui" Then strFntName = "segoe ui"
Next
Label1.Text = "Label1 Text"
Button1.Text = "Button1 Text"
TextBox1.Multiline = True : TextBox1.ScrollBars = ScrollBars.Vertical
TextBox1.Text = "With the people of that age the value of all things was determined by outward show." & _
" As religion had declined in power, it had increased in pomp. The educators" & _
" of the time sought to command respect by display and ostentation. To all this" & _
" the life of Jesus presented a marked contrast. - Ed pg 77 - Ellen G White"
refreshBounds()
CenterToScreen()
End Sub
Private Sub Form5_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
e.Graphics.DrawString("Some GDI drawn text . . .", fnt, Brushes.DarkBlue, CInt(reScale * 30), CInt(reScale * 20))
End Sub
Private Sub Form5_ResizeEnd(sender As Object, e As System.EventArgs) Handles Me.ResizeEnd
If isEvntSus Then Exit Sub
Dim K, L As Integer
K = ClientSize.Width : L = ClientSize.Height
If K = fW And L = fH Then
Exit Sub
ElseIf K = fW And Not L = fH Then
ClientSize = New Size(CInt(L / 0.75), L)
ElseIf Not K = fW And L = fH Then
ClientSize = New Size(K, CInt(K * 0.75))
ElseIf Not K = fW And Not L = fH Then
If K / L < 1.333333 Then
ClientSize = New Size(K, CInt(K * 0.75))
Else
ClientSize = New Size(CInt(L / 0.75), L)
End If
End If
My.Settings.FrmSz = ClientSize.Width.ToString & "," & ClientSize.Height.ToString
refreshBounds()
Invalidate()
End Sub
Private Sub Form5_SizeChanged(sender As Object, e As System.EventArgs) Handles Me.SizeChanged
If WindowState = FormWindowState.Minimized Then Exit Sub
If isMax Then
isMax = False
refreshBounds()
Invalidate()
End If
If WindowState = FormWindowState.Maximized Then
isMax = True
refreshBounds()
Invalidate()
End If
End Sub
Sub refreshBounds()
fW = ClientSize.Width : fH = ClientSize.Height
reScale = fW / 400
fnt = New Font(strFntName, CInt(reScale * 18), FontStyle.Regular, GraphicsUnit.Pixel)
Label1.Location = New Point(CInt(reScale * 30), CInt(reScale * 60))
Button1.SetBounds(CInt(reScale * 200), CInt(reScale * 60), CInt(reScale * 170), CInt(reScale * 40))
TextBox1.SetBounds(CInt(reScale * 30), CInt(reScale * 120), CInt(reScale * 340), CInt(reScale * 150))
Label1.Font = fnt : Button1.Font = fnt : TextBox1.Font = fnt
Text = "Clientsize = { " & fW.ToString & " : " & fH.ToString & " }"
End Sub
Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
MsgBox("Ouiy")
End Sub
End Class
All the pixel related methods will still work correctly except for the screen capture method (I forget what that is at this moment). It always captures the co-ordinates of the machine pixels (as if the user has 100% chosen in display settings.
There is a way to query your machines screen pixel width and height. If you are interested in that -
Imports System.Runtime.InteropServices ' Mr.Monkeyboy provided this code in principal
Public Class Form12
<DllImport("gdi32.dll")> _
Private Shared Function GetDeviceCaps(hdc As IntPtr, nIndex As Integer) As Integer
End Function
Private Sub Form12_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim g As Graphics = Graphics.FromHwnd(IntPtr.Zero)
Dim desktop As IntPtr = g.GetHdc()
'MessageBox.Show(GetDeviceCaps(desktop, 4).ToString & " Physical width mm" & vbCrLf & _
' GetDeviceCaps(desktop, 6).ToString & " Physical height mm" & vbCrLf & _
' GetDeviceCaps(desktop, 8).ToString & " Virtual pixel width" & vbCrLf & _
' GetDeviceCaps(desktop, 10).ToString & " Virtual pixel height" & vbCrLf & _
' GetDeviceCaps(desktop, 118).ToString & " Factory pixel width" & vbCrLf & _
' GetDeviceCaps(desktop, 117).ToString & " Factory pixel height")
MessageBox.Show(GetDeviceCaps(desktop, 116).ToString & " Video Hardware refresh rate Hertz. (FPS).")
End Sub
Public Enum DeviceCap
''' <summary>
''' Device driver version
''' </summary>
DRIVERVERSION = 0
''' <summary>
''' Device classification
''' </summary>
TECHNOLOGY = 2
''' <summary>
''' Horizontal size in millimeters
''' </summary>
HORZSIZE = 4
''' <summary>
''' Vertical size in millimeters
''' </summary>
VERTSIZE = 6
''' <summary>
''' Horizontal width in pixels
''' </summary>
HORZRES = 8
''' <summary>
''' Vertical height in pixels
''' </summary>
VERTRES = 10
''' <summary>
''' Number of bits per pixel
''' </summary>
BITSPIXEL = 12
''' <summary>
''' Number of planes
''' </summary>
PLANES = 14
''' <summary>
''' Number of brushes the device has
''' </summary>
NUMBRUSHES = 16
''' <summary>
''' Number of pens the device has
''' </summary>
NUMPENS = 18
''' <summary>
''' Number of markers the device has
''' </summary>
NUMMARKERS = 20
''' <summary>
''' Number of fonts the device has
''' </summary>
NUMFONTS = 22
''' <summary>
''' Number of colors the device supports
''' </summary>
NUMCOLORS = 24
''' <summary>
''' Size required for device descriptor
''' </summary>
PDEVICESIZE = 26
''' <summary>
''' Curve capabilities
''' </summary>
CURVECAPS = 28
''' <summary>
''' Line capabilities
''' </summary>
LINECAPS = 30
''' <summary>
''' Polygonal capabilities
''' </summary>
POLYGONALCAPS = 32
''' <summary>
''' Text capabilities
''' </summary>
TEXTCAPS = 34
''' <summary>
''' Clipping capabilities
''' </summary>
CLIPCAPS = 36
''' <summary>
''' Bitblt capabilities
''' </summary>
RASTERCAPS = 38
''' <summary>
''' Length of the X leg
''' </summary>
ASPECTX = 40
''' <summary>
''' Length of the Y leg
''' </summary>
ASPECTY = 42
''' <summary>
''' Length of the hypotenuse
''' </summary>
ASPECTXY = 44
''' <summary>
''' Shading and Blending caps
''' </summary>
SHADEBLENDCAPS = 45
''' <summary>
''' Logical pixels inch in X
''' </summary>
LOGPIXELSX = 88
''' <summary>
''' Logical pixels inch in Y
''' </summary>
LOGPIXELSY = 90
''' <summary>
''' Number of entries in physical palette
''' </summary>
SIZEPALETTE = 104
''' <summary>
''' Number of reserved entries in palette
''' </summary>
NUMRESERVED = 106
''' <summary>
''' Actual color resolution
''' </summary>
COLORRES = 108
' Printing related DeviceCaps. These replace the appropriate Escapes
''' <summary>
''' Physical Width in device units
''' </summary>
PHYSICALWIDTH = 110
''' <summary>
''' Physical Height in device units
''' </summary>
PHYSICALHEIGHT = 111
''' <summary>
''' Physical Printable Area x margin
''' </summary>
PHYSICALOFFSETX = 112
''' <summary>
''' Physical Printable Area y margin
''' </summary>
PHYSICALOFFSETY = 113
''' <summary>
''' Scaling factor x
''' </summary>
SCALINGFACTORX = 114
''' <summary>
''' Scaling factor y
''' </summary>
SCALINGFACTORY = 115
''' <summary>
''' Current vertical refresh rate of the display device (for displays only) in Hz
''' </summary>
VREFRESH = 116
''' <summary>
''' Vertical height of entire desktop in pixels
''' </summary>
DESKTOPVERTRES = 117
''' <summary>
''' Horizontal width of entire desktop in pixels
''' </summary>
DESKTOPHORZRES = 118
''' <summary>
''' Preferred blt alignment
''' </summary>
BLTALIGNMENT = 119
End Enum
End Class