我有一个要调整大小的图片框,我需要它保持1:1的纵横比。基本上,宽度和高度都与用户调整大小相同。调整大小可以正常工作,但无法保持宽高比。我该如何更改以包括保持宽高比?
这是调整控件大小时的称呼
Private Sub pbsMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If mouseOnHandle Then
ReleaseCapture()
SendMessage(activeControl.Handle, WM_NCLBUTTONDOWN, CInt(DirectCast(sender, PictureBox).Tag), 0)
If GetCapture = 0 Then mouseOnHandle = False
Application.DoEvents()
End If
End Sub
ReleaseCapture()
<DllImport("user32.dll")> _
Public Shared Function ReleaseCapture() As Boolean
End Function
常量和函数
Public Declare Function GetCapture Lib "user32" Alias "GetCapture" () As Integer
Private Const WM_NCLBUTTONDOWN As Integer = &HA1
答案 0 :(得分:1)
我最终将此功能添加到控件的调整大小事件中
Private Sub maintainAspectRatio()
Dim width As Integer = activeControl.Width
Dim height As Integer = activeControl.Height
If width > height Then
activeControl.Height = activeControl.Width
ElseIf height > width Then
activeControl.Width = activeControl.Height
End If
End Sub
这为我解决了这个问题