专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
用鼠标和键盘控制图片移动源码
2019-04-15 18:37
发布
生成海报
站内文章
/
PIC单片机
15997
0
1246
Public Class Form1 Private WithEvents panel As Panel Private WithEvents pic As PictureBox Private x, y As Integer Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown Select Case e.KeyCode Case Keys.Up panel.AutoScrollPosition = New Point(0 - panel.AutoScrollPosition.X, 1 - panel.AutoScrollPosition.Y) Case Keys.Down panel.AutoScrollPosition = New Point(0 - panel.AutoScrollPosition.X, -1 - panel.AutoScrollPosition.Y) Case Keys.Left panel.AutoScrollPosition = New Point(1 - panel.AutoScrollPosition.X, 0 - panel.AutoScrollPosition.Y) Case Keys.Right panel.AutoScrollPosition = New Point(-1 - panel.AutoScrollPosition.X, 0 - panel.AutoScrollPosition.Y) Case Else Return End Select End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load panel = New Panel With {.BorderStyle = BorderStyle.Fixed3D, .Dock = DockStyle.Fill, .AutoScroll = True} pic = New PictureBox With {.BorderStyle = BorderStyle.None, .SizeMode = PictureBoxSizeMode.AutoSize} panel.Controls.Add(pic) Me.Controls.Add(panel) Using ofd As New OpenFileDialog With {.Filter = "Image|*.bmp;*.jpg;*.png"} If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then pic.Image = Image.FromFile(ofd.FileName) End If End Using End Sub Private Sub pic_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pic.MouseDown If e.Button = Windows.Forms.MouseButtons.Left Then pic.Cursor = Cursors.Hand x = e.X y = e.Y End If End Sub Private Sub pic_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pic.MouseMove If e.Button = Windows.Forms.MouseButtons.Left Then Dim dx As Integer = x - e.X Dim dy As Integer = y - e.Y panel.AutoScrollPosition = New Drawing.Point((dx - panel.AutoScrollPosition.X), (dy - panel.AutoScrollPosition.Y)) End If End Sub Private Sub pic_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pic.MouseUp pic.Cursor = Cursors.Arrow End Sub End Class
Ta的文章
更多
>>
用鼠标和键盘控制图片移动源码
0 个评论
热门文章
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮