怎样控制ScrollBar?

peacock 2000-03-08 06:15:00
我想在移动图形时,让ScrollBar的移动条也同步滚动,而不是拉动ScrollBar来控制图形的滚动,怎么办?谢谢各位!!!
...全文
285 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
grievefish 2000-03-10
  • 打赏
  • 举报
回复
我水平有限!
只能作到这样了!
至于坐标吗!SCALEMODE设成3。
peacock 2000-03-10
  • 打赏
  • 举报
回复
非常感谢各位的帮助!特别是grievefish的解答很好!不过图像太抖动,坐标也好像有写问题。
Un1 2000-03-09
  • 打赏
  • 举报
回复
为了不出现循环调用,应该在PictureBox的MouseMove内直接设置ScrollBar, 而在ScrollBar的Change事件内Move PictureBox.
grievefish 2000-03-09
  • 打赏
  • 举报
回复
设置两个PICTUREBOX,一个作容器PICTURERP,另PICTUREIM一个用于加载图片;
在PICTUREIM_MOUSEDOWN()和PICTURE_KEYDOWN中编写一些处理代码;
其他我还没想好呢,等我想好了在……
~_~

ltp3 2000-03-09
  • 打赏
  • 举报
回复
ScrollBar.Value=
grievefish 2000-03-09
  • 打赏
  • 举报
回复
不好意思!
MOVE忘了改了!
MOVE都改成IMOVE.
&_&
grievefish 2000-03-09
  • 打赏
  • 举报
回复
Dim oldx As Single
Dim oldy As Single
Dim newx As Single
Dim newy As Single
Dim move As Boolean

Private Sub Form_Load()
pictureim.Picture = LoadPicture("c:\windows\安装程序.bmp")
End Sub
Private Sub Form_Resize()
On Error Resume Next
Picturerp.Width = Form1.ScaleWidth - VScroll1.Width
Picturerp.Height = Form1.ScaleHeight - HScroll1.Height
HScroll1.Width = Picturerp.Width
HScroll1.Top = Picturerp.Height
VScroll1.Height = Picturerp.Height
VScroll1.Left = Form1.ScaleWidth - VScroll1.Width
End Sub

Private Sub Pictureim_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
move = True
oldx = X
oldy = Y
End Sub


Private Sub Pictureim_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next

Dim movex As Single
Dim movey As Single
newx = X
newy = Y
If move Then '是否可移动
movex = newx - oldx '水平移动量
movey = newy - oldy '垂直移动量

If pictureim.Top >= 0 Then '是否下移到极限
pictureim.Top = 0
If newy >= oldy Then '是否继续下移
oldy = newy
movey = 0
End If
End If
If pictureim.Top <= Picturerp.Height - pictureim.Height Then
pictureim.Top = Picturerp.Height - pictureim.Height
If newy <= oldy Then
movey = 0
End If
End If
pictureim.Top = pictureim.Top + movey
VScroll1.Value = pictureim.Top / (Picturerp.Height - _
pictureim.Height) * 100
If pictureim.Left >= 0 Then
pictureim.Left = 0
If newx >= oldy Then
oldx = newx
monex = 0
End If
End If
If pictureim.Left <= Picturerp.Width - pictureim.Width Then
pictureim.Left = Picturerp.Width - pictureim.Width
If newx <= oldy Then
oldy = newy
movey = 0
End If
End If
HScroll1.Value = pictureim.Left / (Picturerp.Width - _
pictureim.Width) * 100
pictureim.Left = pictureim.Left + movex
End If

End Sub

Private Sub pictureim_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
move = False
End Sub
水平移动有些抖动,还请别人指点!
zjy 2000-03-08
  • 打赏
  • 举报
回复
我曾用VC++做过,
首先确定图形移动范围用SetScrollRange设定其父窗口
(也许是父父..窗口)的ScrollBar
在图形窗口的WM_MOVE处理中得到相对位置后再用SetScrollPos
去设定其父窗口的ScrollBar位置
我要回家了,祝好运!
peacock 2000-03-08
  • 打赏
  • 举报
回复
zjy:能举例吗?
zjy 2000-03-08
  • 打赏
  • 举报
回复
看Win32 API函数:
SetScrollPos,SetScrollRange...

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧