[英]Resize picturebox and maintain aspect ratio (1:1) vb.net
我有一个要调整大小的图片框,我需要它保持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
我最终将此功能添加到控件的调整大小事件中
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
这为我解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.