gpt4 book ai didi

vb.net - 使用面板的 Autoscroll = True 在图片框中进行矩形选择以裁剪图像时自动移动滚动条

转载 作者:行者123 更新时间:2023-12-04 18:07:24 27 4
gpt4 key购买 nike

我在面板顶部有一个图片框。我有一个矩形选区,可用于选择图像的一部分进行裁剪。由于我已将面板的自动滚动属性设置为 True,并且图像在图片框很大,我有滚动条。但是为了选择图像的一部分进行裁剪,我需要将矩形拖到我看不到的范围之外。当鼠标到达图片框的最右边时,我不能这样做。我想以一种方式设计它,当鼠标到达最右边时,我的滚动条应该自动向右移动。但是使用 Autoscroll 属性我无法获得滚动条值。任何解决方法可用于此问题?

最佳答案

使用 Timer 来移动 AutoScrollPosition 属性可能会更流畅一些:

Private horzMove As ArrowDirection = -1
Private vertMove As ArrowDirection = -1

Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Then
If Panel1.AutoScrollPosition.X + e.Location.X > Panel1.ClientSize.Width Then
horzMove = ArrowDirection.Right
ElseIf Panel1.AutoScrollPosition.X + e.Location.X < 0 Then
horzMove = ArrowDirection.Left
Else
horzMove = -1
End If
If Panel1.AutoScrollPosition.Y + e.Location.Y > Panel1.ClientSize.Height Then
vertMove = ArrowDirection.Down
ElseIf Panel1.AutoScrollPosition.Y + e.Location.Y < 0 Then
vertMove = ArrowDirection.Up
Else
vertMove = -1
End If
End If
End Sub

Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
horzMove = -1
vertMove = -1
End Sub

确保计时器已启用:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If horzMove > -1 Or vertMove > -1 Then
Dim newLeft As Integer = -Panel1.AutoScrollPosition.X
Dim newTop As Integer = -Panel1.AutoScrollPosition.Y
Select Case horzMove
Case ArrowDirection.Left
newLeft = -Panel1.AutoScrollPosition.X - 32
Case ArrowDirection.Right
newLeft = -Panel1.AutoScrollPosition.X + 32
End Select
Select Case vertMove
Case ArrowDirection.Down
newTop = -Panel1.AutoScrollPosition.Y + 32
Case ArrowDirection.Up
newTop = -Panel1.AutoScrollPosition.Y - 32
End Select
Panel1.AutoScrollPosition = New Point(newLeft, newTop)
End If
End Sub

关于vb.net - 使用面板的 Autoscroll = True 在图片框中进行矩形选择以裁剪图像时自动移动滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23496078/

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