Link to home
Start Free TrialLog in
Avatar of Jess31
Jess31

asked on

vb.net winforms sizing/resolution?

I am using visual studio with vb.net and winforms.
I moved from a desktop to a laptop. The laptop screen resolution is 3200 X 1800 and a second monitor attached which is 1920 X 1080. When I open a new form, I stretch it a bit and on the second monitor I can see in the properties Size.Width a size greater than 1920 without even filling the complete screen. On the laptop screen I set the form to larger than 3200 and it doesn't even fill the complete screen.
What does this Size reflect? It does not seem to be pixels based on what I am finding. And is there away to make it reflect pixels?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

What does this Size reflect? It does not seem to be pixels based on what I am finding. And is there away to make it reflect pixels?

try look for the Anchor property of your controls, and select the direction you want it to be sticky so when the form is resized, it should able to adjust its size accordingly.

User generated image
In addition, you may also look for these 2 properties of your controls
  • MaximumSize
  • MinimumSize
WinForm size is in pixels. However, you can not set form size larger then screen size from managed code. To check allowed form size use SystemInformation.MaxWindowTrackSize.Width (or height)
If you still need to have larger size you need use WinAPI:
<Runtime.InteropServices.DllImport("user32.dll")>
Private Shared Function MoveWindow(hWnd As IntPtr, X As Integer, Y As Integer, nWidth As Integer, nHeight As Integer, bRepaint As Boolean) As Boolean
End Function

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Me.MaximumSize = New Size(4000, 4000)
    MoveWindow(Me.Handle, 0, 0, 4000, 4000, True)
    Me.UpdateBounds()
End Sub

Open in new window

Avatar of Jess31
Jess31

ASKER

Perhaps I'm not explaining well. Let me try better. My laptop monitor is very high res, the secondary monitor is just 1080 X 1920. But no matter which monitor I use vs on it assumes I am on the high res monitor and create forms as such, and dpi as such. How can I tell vs that my dpi is different?
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial