VB form The control automatically changes in the form (source code)

xiaoxiao2021-03-06  40

Source code download: http://blog.blogchina.com/upload/2004-12-07/20041207155830520878.RAR In development, developers often need to control the size of the control size to adapt the window, so that the software is also available at different resolutions It looks a proportional coordination. So how can you let the controls in the form automatically change with the form of the form?

I think there is a kind of original method is useful, not letting the form to maximize: such as flying food and drink software ...

Of course, this method is detour. The software developed will definitely can't watch it. Ok, let us lead to this very useful, professional model. --------------- -------------------------------------------------- --------------- Option ExplicitPrivate FormoldWidth As long 'Save the original Width of the FormoldHeight As long' Save the original height of the form

'Before calling this function first calls 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 0nd Sub

'Change the size of each component in the scale, call ResizeInit function before calling ResizeInit function PUBLIC SUB Resizeform (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 scale On Error Resume Next For Each Obj In FormName StartPos = 1 For i = 0 TO 4 'Read control of the original location and size Temppos = INSTR (startpos, obj.tag, "", vbtextcompare) ife temppos> 0 THEN POS (i) = MID (Obj.tag, StartPos, Temppos - StartPOS) STARTPOS = Temppos 1 Else POS (i) = 0 End if 'Deactivation and Change Size Obj.move Pos (0) * Scalex, POS (1) * Scaley , POS (2) * Scalex, POS (3) * Scaley Next I next obj on error goto 0nd sub 'development software, put this MODAL load in the program. Then add the following code: Private Sub Form_Load () Call Resizeinit (ME ) 'End Sub must be added when the program is loaded

Private Sub Form_Resize () Call Resizeform (ME) 'Make sure the control is changed when the form changes END SUB -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- -

OK, so your software can automatically change the control with the form in the form!

Your software has become so ugly from the appearance. And the proportion is also coordinated at a large resolution.

转载请注明原文地址:https://www.9cbs.com/read-86121.html

New Post(0)