VB中,picturebox添加滚动条的相关问题
为什么滚动条和picture2中的图片一起动起来了呢?以下是测试代码:PrivateSubCommand1_Click()OnErrorGoToErrExitCommon...
为什么滚动条和picture2中的图片一起动起来了呢?
以下是测试代码:
Private Sub Command1_Click()On Error GoTo ErrExitCommonDialog1.Filter = "bitmap file(*.bmp)|*.bmp|all file(*.*)|*.*"CommonDialog1.FilterIndex = 1CommonDialog1.ShowOpenPicture2.Picture = LoadPicture(CommonDialog1.FileName)VScroll1.Min = 0HScroll1.Min = 0VScroll1.Max = Picture2.Height - Picture1.HeightHScroll1.Max = Picture2.Width - Picture1.WidthIf HScroll1.Max < 0 ThenHScroll1.Enabled = FalseEnd IfIf VScroll1.Max < 0 ThenVScroll1.Enabled = FalseEnd IfErrExit:End Sub
Private Sub Form_Load()Picture2.Left = 0Picture2.Top = 0Picture2.Width = Picture1.WidthPicture2.Height = Picture1.HeightVScroll1.Min = 0HScroll1.Min = 0VScroll1.Max = Picture2.Height - Picture1.HeightHScroll1.Max = Picture2.Width - Picture1.WidthIf HScroll1.Max < 0 ThenHScroll1.Enabled = FalseEnd IfIf VScroll1.Max < 0 ThenVScroll1.Enabled = FalseEnd IfEnd Sub
Private Sub HScroll1_Change()Picture2.Left = -HScroll1.ValueEnd Sub
Private Sub VScroll1_Change()Picture2.Top = -VScroll1.ValueEnd Sub
结果如下: 展开
以下是测试代码:
Private Sub Command1_Click()On Error GoTo ErrExitCommonDialog1.Filter = "bitmap file(*.bmp)|*.bmp|all file(*.*)|*.*"CommonDialog1.FilterIndex = 1CommonDialog1.ShowOpenPicture2.Picture = LoadPicture(CommonDialog1.FileName)VScroll1.Min = 0HScroll1.Min = 0VScroll1.Max = Picture2.Height - Picture1.HeightHScroll1.Max = Picture2.Width - Picture1.WidthIf HScroll1.Max < 0 ThenHScroll1.Enabled = FalseEnd IfIf VScroll1.Max < 0 ThenVScroll1.Enabled = FalseEnd IfErrExit:End Sub
Private Sub Form_Load()Picture2.Left = 0Picture2.Top = 0Picture2.Width = Picture1.WidthPicture2.Height = Picture1.HeightVScroll1.Min = 0HScroll1.Min = 0VScroll1.Max = Picture2.Height - Picture1.HeightHScroll1.Max = Picture2.Width - Picture1.WidthIf HScroll1.Max < 0 ThenHScroll1.Enabled = FalseEnd IfIf VScroll1.Max < 0 ThenVScroll1.Enabled = FalseEnd IfEnd Sub
Private Sub HScroll1_Change()Picture2.Left = -HScroll1.ValueEnd Sub
Private Sub VScroll1_Change()Picture2.Top = -VScroll1.ValueEnd Sub
结果如下: 展开
1个回答
展开全部
滚动条要放在Picture1或窗体上,不要放在Picture2上,不然的话,Picture2移动的时候滚动条会跟着移动
追问
哦,我试试 ,谢谢
追答
PictureBox控件除了用来显示图片,它还有个重要作用就是容器控件,所谓容器就是说它可以包含其他控件,而这些被包含的控件就变成了它的子控件,当这个PictureBox控件移动时,它的子控件也会跟着移动。效果上看起来就像是“窗体中的窗体”,事实上这才是它的主要用途。如果仅仅是为了显示图片,可以用Image控件,可以节约很多内存资源。比如你的程序就可以在Picture1内包含Image1,效果一样、效率却要高一些。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询