vb中 怎么样给picturebox加滚动条?
如果picturebox这个控件,我不加载图片,只想把这个控件做为一个画布,直接在上面画图形,当图形超出picturebox控件的高度时,自动出现滚动条。怎么实现?...
如果picturebox这个控件,我不加载图片,只想把这个控件做为一个画布,直接在上面画图形,当图形超出picturebox控件的高度时,自动出现滚动条。怎么实现?
展开
1个回答
展开全部
首先给工程(Project)添加一个OCX控件,单击选单上的工程(Project)选单项,在弹出的下拉选单中点击组件(Components),选中其中的"Microsoft Common Dialog Control 5.0",确定完成加载工作;然后画一个PictureBox,采用VB提供的默认名字Picture1, 再在Picture1上面画一个PictureBox,默认名字为Picture2,注意别忘了设置:Picture2.AutoSize=TRUE;接着,加上水平和垂直滚动条,默认名字分别为:HScroll1,VScroll1;以后加载图形到Picture2上,就可以了;最后,在窗体中引入其它控件:一个按钮(Command),默认名为Command1和一个"Microsoft Common Dialog Control",默认名为CommonDialog1。具体VB代码如下:
Private Sub Form-Load()
Picture2.Left = 0
Picture2.Top = 0
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
VScroll1.Min = 0
HScroll1.Min = 0
HScroll1.Min = 0
VScroll1.Max = Picture2.Height - Picture1.Height
HScroll1.Max = Picture2.Width - Picture1.Width
If HScroll1.Max 〈 0 Then HScroll1.Enabled = False
If VScroll1.Max 〈 0 Then VScroll1.Enabled = False
End Sub
Private Sub Command-Click()
On Error GoTo ErrExit
CommonDialog1.Filter =
"Bitmap file(*.bmp)|*.bmp|All File(*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowOpen
Picture2.Picture = LoadPicture(CommonDialog1.filename)
VScroll1.Min = 0
HScroll1.Min = 0
VScroll1.Max = Picture2.Height - Picture1.Height
HScroll1.Max = Picture2.Width - Picture1.Width
If HScroll1.Max 〈 0 Then HScroll1.Enabled = False
If VScroll1.Max 〈 0 Then VScroll1.Enabled = False
ErrExit:
End Sub
Private Sub HScroll1-Change()
Picture2.Left = -HScroll1.Value
End Sub
Private Sub VScroll1-Change()
Picture2.Top = -VScroll1.Value
End Sub
---- 该程序通过点击Command1按钮,在弹出的对话框中选择一个图形文件加载到Picture2中,利用水平和垂直滚动条就可以实现图片的滚动。
Private Sub Form-Load()
Picture2.Left = 0
Picture2.Top = 0
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
VScroll1.Min = 0
HScroll1.Min = 0
HScroll1.Min = 0
VScroll1.Max = Picture2.Height - Picture1.Height
HScroll1.Max = Picture2.Width - Picture1.Width
If HScroll1.Max 〈 0 Then HScroll1.Enabled = False
If VScroll1.Max 〈 0 Then VScroll1.Enabled = False
End Sub
Private Sub Command-Click()
On Error GoTo ErrExit
CommonDialog1.Filter =
"Bitmap file(*.bmp)|*.bmp|All File(*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowOpen
Picture2.Picture = LoadPicture(CommonDialog1.filename)
VScroll1.Min = 0
HScroll1.Min = 0
VScroll1.Max = Picture2.Height - Picture1.Height
HScroll1.Max = Picture2.Width - Picture1.Width
If HScroll1.Max 〈 0 Then HScroll1.Enabled = False
If VScroll1.Max 〈 0 Then VScroll1.Enabled = False
ErrExit:
End Sub
Private Sub HScroll1-Change()
Picture2.Left = -HScroll1.Value
End Sub
Private Sub VScroll1-Change()
Picture2.Top = -VScroll1.Value
End Sub
---- 该程序通过点击Command1按钮,在弹出的对话框中选择一个图形文件加载到Picture2中,利用水平和垂直滚动条就可以实现图片的滚动。
参考资料: http://99yangyanglove.bokee.com/3209336.html
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询