' Change controls size and fonts to fit screen working area.ĭim rw As Double = (Me.Width - cw) / cw ' Ratio change of original form width.ĭim rh As Double = (Me.Height - ch) / ch ' Ratio change of original form height. Private Sub Main_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize ' Set the location so the entire form is visible. Me.Size = New (workingRectangle.Width - 5, workingRectangle.Height - 5) ' Set the size of the form slightly less than size of working rectangle. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Retrieve the working rectangle from the Screen class using the PrimaryScreen and the WorkingArea properties.ĭim workingRectangle As = Option Strict Onĭim ch As Integer ' Forms current Height.ĭim iw As Integer = 1280 ' Forms initial width.ĭim ih As Integer = 760 ' Forms initial height. Resize controls to match forms new size, and the fonts too if it hits a certain res over original.
Vb.net 2013 Found some of this code on this site, can't find it now to give credit!:-( Made at 15.5 laptop res of 1780x760, changes to users primary screen working area. The way I'm doing it is clean but uses "late binding" and requires Option Strict Off. NOTE that I'm using reflection to see if each control has the properties we need to adjust. If (.GetType.GetProperty("Left").CanRead) Then. If (.GetType.GetProperty("Top").CanRead) Then. If (.GetType.GetProperty("Height").CanRead) Then. If (.GetType.GetProperty("Width").CanRead) Then. i.e., something like: Dim DesignScreenWidth As Integer = 1600ĭim CurrentScreenWidth As Integer = ĭim CurrentScreenHeight As Integer = ĭim RatioX as Double = CurrentScreenWidth / DesignScreenWidthĭim RatioY as Double = CurrentScreenHeight / DesignScreenHeight Just iterate through the VB controls and adjust their sizes based on the ratio of the new screen resolution to your design screen resolution. OK, this is just about as simple as it gets.