想让窗体的大小随着长或宽的改变而自动按比例调整,即改变长,宽就自动相应改变。可是,如下写代码后,一旦运行,调整窗体大小时,窗体会有改变趋势,但是也马上出现意外的死机现象。郁闷,到底请教该如何实现呢?
相应代码如下:
Private FormOldWidth As Long
'保存窗体的原始宽度
Private FormOldHeight As Long
'保存窗体的原始高度
Private Sub Form_Load()
FormOldWidth = me.Width
FormOldHeight = me.Height
End Sub
Private Sub Form_Resize()
changebili = me.Width / FormOldWidth
'保存窗体宽度缩放比例
If me.Width <> FormOldWidth Then
me.Height = FormOldHeight * changebili
End If
If me.height<> FormOldheight Then
me.width= FormOldwidth * changebili
End If End Sub
相应代码如下:
Private FormOldWidth As Long
'保存窗体的原始宽度
Private FormOldHeight As Long
'保存窗体的原始高度
Private Sub Form_Load()
FormOldWidth = me.Width
FormOldHeight = me.Height
End Sub
Private Sub Form_Resize()
changebili = me.Width / FormOldWidth
'保存窗体宽度缩放比例
If me.Width <> FormOldWidth Then
me.Height = FormOldHeight * changebili
End If
If me.height<> FormOldheight Then
me.width= FormOldwidth * changebili
End If End Sub
Option ExplicitDim dK As Double
Dim lLastWidth As Long
Dim lLastHeight As LongPrivate Sub Form_Load()
dK = Me.Width / Me.Height
End SubPrivate Sub Form_Resize()
If Me.WindowState = 0 Then
If lLastWidth <> Me.Width And lLastHeight <> Me.Height Then
Me.Height = Me.Width / dK
Else
If lLastWidth <> Me.Width Then
Me.Height = Me.Width / dK
Else
Me.Width = dK * Me.Height
End If
End If
lLastWidth = Me.Width
lLastHeight = Me.Height
End If
End Sub