首先給工程(project)新增一個ocx控制元件,單擊選單上的工程(project)選單項,在彈出的下拉選單中點選元件(components),選中其中的"microsoftcommondialogcontrol5.0",確定完成載入工作;然後畫一個picturebox,採用vb提供的預設名字picture1,再在picture1上面畫一個picturebox,預設名字為picture2,注意別忘了設定:picture2.autosize=true;接著,加上水平和垂直捲軸,預設名字分別為:hscroll1,vscroll1;以後載入影象到picture2上,就能了;最後,在窗體中引入其他控制元件:一個按鈕(command),預設名為command1和一個"microsoftcommondialogcontrol",預設名為commondialog1。具體vb程式碼如下:
privatesubform-load()
picture2.left=0
picture2.top=0
picture2.width=picture1.width
picture2.height=picture1.height
vscroll1.min=0
hscroll1.min=0
vscroll1.max=picture2.height-picture1.height
hscroll1.max=picture2.width-picture1.width
ifhscroll1.max〈0thenhscroll1.enabled=false
ifvscroll1.max〈0thenvscroll1.enabled=false
endsub
privatesubcommand-click()
onerrorgotoerrexit
commondialog1.filter=
"bitmapfile(*.bmp)|*.bmp|allfile(*.*)|*.*"
commondialog1.filterindex=1
commondialog1.showopen
picture2.picture=loadpicture(commondialog1.filename)
errexit:
privatesubhscroll1-change()
picture2.left=-hscroll1.value
privatesubvscroll1-change()
picture2.top=-vscroll1.value
首先給工程(project)新增一個ocx控制元件,單擊選單上的工程(project)選單項,在彈出的下拉選單中點選元件(components),選中其中的"microsoftcommondialogcontrol5.0",確定完成載入工作;然後畫一個picturebox,採用vb提供的預設名字picture1,再在picture1上面畫一個picturebox,預設名字為picture2,注意別忘了設定:picture2.autosize=true;接著,加上水平和垂直捲軸,預設名字分別為:hscroll1,vscroll1;以後載入影象到picture2上,就能了;最後,在窗體中引入其他控制元件:一個按鈕(command),預設名為command1和一個"microsoftcommondialogcontrol",預設名為commondialog1。具體vb程式碼如下:
privatesubform-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
ifhscroll1.max〈0thenhscroll1.enabled=false
ifvscroll1.max〈0thenvscroll1.enabled=false
endsub
privatesubcommand-click()
onerrorgotoerrexit
commondialog1.filter=
"bitmapfile(*.bmp)|*.bmp|allfile(*.*)|*.*"
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
ifhscroll1.max〈0thenhscroll1.enabled=false
ifvscroll1.max〈0thenvscroll1.enabled=false
errexit:
endsub
privatesubhscroll1-change()
picture2.left=-hscroll1.value
endsub
privatesubvscroll1-change()
picture2.top=-vscroll1.value
endsub