关于vb中 picturebox和滚动条 5
picture2作容器,里面有picture1(大图autosize,横竖滚动条),怎么使picture2透明,让底下的picture不被挡住,并且使滚动条不随pictu...
picture2作容器,里面有picture1(大图autosize , 横竖滚动条),怎么使picture2透明,让底下的picture不被挡住,并且使滚动条不随picture2 的透明而不可见
展开
2个回答
展开全部
首先给工程(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中,利用水平和垂直滚动条就可以实现图片的滚动。
满意请采纳。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询