一道VB编程题,如何设计使图片随水平和垂直滚动条上下左右移动?请给出具体代码?
2个回答
展开全部
这个简单啊~!首先你要把PictureBox放在一个容器中,强烈推荐使用PictureBox作为容器。也就是在PictureBox中画子PictureBox。这样比较好操作。也便于你日后的处理!~废话不多说。
假设Picture2是Picture1的容器,水平滚动条的名称为HSX,垂直滚动条名称为VSY。那么代码可以这样写:
Private Sub Form_Load()
Picture1.AutoSize = True
Picture1.Picture = LoadPicture("这里加载你指定位置的图片")
If Picture1.Width > Picture2.Width Then
HSX.Enabled = True
HSX.Max = Picture1.Width - Picture2.Width
Else
HSX.Enabled = False
End If
If Picture1.Height > Picture2.Height Then
VSY.Enabled = True
VSY.Max = Picture1.Height - Picture2.Height
Else
VSY.Enabled = False
End If
End Sub
Private Sub HSX_Change()
Picture1.Left = (-1) * HSX.Value
End Sub
Private Sub HSX_Scroll()
Call HSX_Change
End Sub
Private Sub VSY_Change()
Picture1.Top = (-1) * VSY.Value
End Sub
Private Sub VSY_Scroll()
Call VSY_Change
End Sub
假设Picture2是Picture1的容器,水平滚动条的名称为HSX,垂直滚动条名称为VSY。那么代码可以这样写:
Private Sub Form_Load()
Picture1.AutoSize = True
Picture1.Picture = LoadPicture("这里加载你指定位置的图片")
If Picture1.Width > Picture2.Width Then
HSX.Enabled = True
HSX.Max = Picture1.Width - Picture2.Width
Else
HSX.Enabled = False
End If
If Picture1.Height > Picture2.Height Then
VSY.Enabled = True
VSY.Max = Picture1.Height - Picture2.Height
Else
VSY.Enabled = False
End If
End Sub
Private Sub HSX_Change()
Picture1.Left = (-1) * HSX.Value
End Sub
Private Sub HSX_Scroll()
Call HSX_Change
End Sub
Private Sub VSY_Change()
Picture1.Top = (-1) * VSY.Value
End Sub
Private Sub VSY_Scroll()
Call VSY_Change
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询