vb.net controls (including fonts) are scaled proportionally with the form __.net

Source: Internet
Author: User

Public Class FRMDL

Dim x As Single = 0

Dim y As Single = 0

Private Sub frmdl_load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load

x = Me.Width

y = me.height

Settag (Me)

End Sub

' recursively takes the original size and position of the control, using tag to record

Private Sub Settag (ByVal obj as Object)

For all con as control in obj. Controls

Con. Tag = con. Width & ":" & con. Height & ":" & con. Left & ":" & con. Top & ":" & con. Font.Size

' If it is a container control, it continues to record recursively

If con. Controls.Count > 0 Then

Settag (Con)

End If

Next

End Sub

' Recursively reset the size and position of the control

Private Sub Setcontrols (ByVal newx as single, ByVal newy as single, ByVal obj as Object)

For all con as control in obj. Controls

Con. AutoSize = False

Dim MyTag () as String = con. Tag.ToString.Split (":")

Con. Width = MyTag (0) * newx

Con. Height = MyTag (1) * Newy

Con. left = MyTag (2) * NEWX

Con. top = MyTag (3) * Newy

' Calculate font scaling, scaling fonts

Dim CurrentSize as Single = (MyTag (1) * Newy * MYTAG (4))/MyTag (1)

Con. Font = New font (con. Font.Name, CurrentSize, _

Con. Font.style, Con. Font.unit)

' If it is a container control, the recursion continues to scale

If con. Controls.Count > 0 Then

Setcontrols (newx, newy, con)

End If

Next

End Sub

Private Sub frmdl_resize (ByVal sender as Object, ByVal e as System.EventArgs) Handles me.resize

' Get the size of the form now, and then calculate the zoom scale based on the original size

Dim newx as Single = me.width/x

Dim Newy as Single = me.height/y

Setcontrols (Newx, Newy, Me)

End Sub

End Class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.