很多人 还老在问VB窗口大小的问题
不多废话了,贴代码
Option Explicit Private nWndHeight As Long Private nWndWidth As Long Private nControl As Long Private lpTop() As Long Private lpLeft() As Long Private lpWidth() As Long Private lpHeight() As Long Private Sub Form_Load() Me.GetControlSize Me.WindowState = 2 '...... End Sub Public Sub GetControlSize() Dim c As Control, i As Integer nControl = 0 i = Me.ScaleMode Me.ScaleMode = 1 On Local Error Resume Next nWndWidth = Me.Width nWndHeight = Me.Height For Each c In Me.Controls ReDim Preserve lpTop(nControl) ReDim Preserve lpLeft(nControl) ReDim Preserve lpWidth(nControl) ReDim Preserve lpHeight(nControl) lpTop(nControl) = c.Top lpLeft(nControl) = c.Left lpWidth(nControl) = c.Width lpHeight(nControl) = c.Height nControl = nControl + 1 Next Me.ScaleMode = i End Sub Public Sub SetControlSize() ' Dim c As Control, i As Integer Dim p As Long i = Me.ScaleMode Me.ScaleMode = 1 For Each c In Me.Controls c.Top = Me.Height * lpTop(p) / nWndHeight c.Left = Me.Width * lpLeft(p) / nWndWidth c.Width = Me.Width * lpWidth(p) / nWndWidth c.Height = Me.Height * lpHeight(p) / nWndHeight p = p + 1 Next Me.ScaleMode = i End Sub Private Sub Form_Resize() Me.SetControlSize End Sub
本文提供了一段VB代码,用于实现窗口大小变化时自动调整控件的位置及尺寸。通过记录初始状态下的窗口尺寸和各控件位置,可在窗口大小改变时按比例调整所有控件。
7401

被折叠的 条评论
为什么被折叠?



