gpt4 book ai didi

.net - 在缩放时如何避免平移超过嵌套在 Panel 中的 PictureBox 控件的边缘?

转载 作者:行者123 更新时间:2023-12-05 00:56:00 25 4
gpt4 key购买 nike

我想知道如何更改我的代码以防止在 PictureBox 放大时和处于正常状态时平移超过 PictureBox 的边缘。如果可能的话,我还想知道如何让它在鼠标悬停的当前位置缩放并在缩放时保持图像质量。任何帮助将不胜感激。

这里是缩放的代码:

Private Sub PictureBox_MouseWheel(sender As System.Object,
e As MouseEventArgs) Handles PictureBox1.MouseWheel
If e.Delta <> 0 Then
If e.Delta <= 0 Then
If PictureBox1.Width < 500 Then Exit Sub
Else
If PictureBox1.Width > 2000 Then Exit Sub
End If

PictureBox1.Width += CInt(PictureBox1.Width * e.Delta / 1000)
PictureBox1.Height += CInt(PictureBox1.Height * e.Delta / 1000)
End If

End Sub

这是我正在使用的平移代码:

Private Offset As Point
Private Sub Picturebox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Offset = e.Location
End Sub
Private Sub Picturebox1_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
PictureBox1.Select()
If e.Button = Windows.Forms.MouseButtons.Left Then
PictureBox1.Left += e.X - Offset.X
PictureBox1.Top += e.Y - Offset.Y
End If
End Sub

最佳答案

您的代码进行拖放而不是平移,调整大小而不是缩放。如果您想平移和缩放,请检查 Stackoverflow 上的这些问题:

同时检查一下:

Creating a scrollable and zoomable image viewer in C# Part 4

还有这个:

PictureBox with zooming and scrolling - 一个工作项目,但是,它不使用 MouseMove 进行平移,因此您需要使用滚动条。缩放有效。语言是 C#。用 VS 2003 编写 - 需要转换。

关于.net - 在缩放时如何避免平移超过嵌套在 Panel 中的 PictureBox 控件的边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13505561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com