Control in development, developers often need to control the size of the control to fit the size of the window, so that the software at different resolutions also appear proportional coordination.
So how do you make a control in a form automatically change with the form?
I think there is a primitive way to be useful, do not allow the form to maximize: such as flying food software ...
Of course, this method is a detour. The software developed will certainly not look good.
Well, let's draw the following this very useful, more professional model bar.
--------------------------------------------------------------------------------
Option Explicit
Private Formoldwidth as Long
' Save the original width of the form
Private Formoldheight as Long
' Save the original height of the form
' Call this function before calling Resizeform
Public Sub Resizeinit (FormName as Form)
Dim OBJ as Control
Formoldwidth = Formname.scalewidth
Formoldheight = Formname.scaleheight
On Error Resume Next
For each Obj in FormName
Obj.tag = Obj.left & "" & Obj.top & "& Obj.width &" "& Obj.height &" "
Next OBJ
On Error GoTo 0
End Sub
' Proportionally change the size of each component within the form, call the Resizeinit function before calling Resizeform
Public Sub Resizeform (FormName as Form)
Dim Pos (4) as Double
Dim I as long, temppos as long, startpos as Long
Dim OBJ as Control
Dim ScaleX as double, ScaleY as double
ScaleX = Formname.scalewidth/formoldwidth
' Save form width scaling
ScaleY = Formname.scaleheight/formoldheight
' Save form height scaling
On Error Resume Next
For each Obj in FormName
startpos = 1
For i = 0 to 4
' Read the original position and size of the control
Temppos = InStr (startpos, Obj.tag, "", vbTextCompare)
If temppos > 0 Then
Pos (i) = Mid (Obj.tag, startpos, Temppos-startpos)
startpos = Temppos + 1
Else
Pos (i) = 0
End If
' Reposition and resize controls based on the original position of the control and how much the form changes size
Obj.move POS (0) * ScaleX, POS (1) * ScaleY, POS (2) * ScaleX, POS (3) * ScaleY
Next I
Next OBJ
On Error GoTo 0
End Sub
' When developing the software, load the modal into the program. Then add the following code:
Private Sub Form_Load ()
Call Resizeinit (Me) ' must join when the program is loaded
End Sub
Private Sub form_resize ()
Call Resizeform (Me) ' Make sure the controls change when the form changes
End Sub
--------------------------------------------------------------------------------
OK, so your software can automatically change the size of the controls on the form with the form!
Your software is at least as ugly as it looks. And the larger resolution also appears to be proportional.
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.