在vb中,我想通过picturebox控件或image控件浏览某文件夹下的所有jpg图片,通过两个按钮(“上一副图片”,“下一副图片”)来浏览,有两个问题:
1,怎么实现浏览图片的功能?
2,我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?使用滚动条可以吗?怎么使用滚动条来实现??谢谢!!!
1,怎么实现浏览图片的功能?
2,我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?使用滚动条可以吗?怎么使用滚动条来实现??谢谢!!!
解决方案 »
- vb打包,是否必须加上mscomctl和mscomct2?
- 请问用vb6输出一个JPG图片文件的方法
- 我想在关机的时候,程序能退出死循环,为什么以下代码会不行?
- 大家谁可以提供一个可用的wav转mp3的控件,或者dll.我找了好多都不能用
- 英雄帖!投票选举本栏目的高手、大侠,顺便看看有没自己的名字啊!
- 在 windows server 2003 环境下无法使用 msdn 6,提示不能打开文件
- 请问有没有办法设置ToolBar的底图,如说是CoolBar的免进,其他欢迎,谢谢
- B2C 客服系统
- VB 对 ACCESS 查询的问题
- 我想让.ocx 文件和.exe文件合并为一个文件,怎么办?
- 音乐文件名字修改问题?谢了!
- 判断文件是否存在
image控件类似//我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?使用滚动条可以吗?怎么使用滚动条来实现??谢谢!!!可以,参考:http://community.csdn.net/Expert/topic/3263/3263473.xml?temp=.2826044
直接使用image控件作为加载图片的控件,loadpicture函数.
pciturebox作为容器,实现image控件在picturebox容器内的移动.那么就用滚动条实现.
'Form1中放一个PictureBox: Picture1
'Picture1中放一个Image: Image1
'一个HScrollBar: HScroll1
'一个VScrollBar: VScroll1Private Sub Form_Load()
With Image1
.Move 0, 0
.Picture = LoadPicture("c:\windows\logow.sys")
'如果这句出错,请改为其他的图片文件
Picture1.Move 0, 0, .Width \ 2, .Height \ 2
End With
With Picture1
HScroll1.Move 0, .ScaleHeight - 255, .ScaleWidth - 255, 255
HScroll1.Max = .ScaleWidth + 255 + 255 \ 2
HScroll1.LargeChange = .ScaleWidth / 50
HScroll1.SmallChange = .ScaleWidth / 50
VScroll1.Move .ScaleWidth - 255, 0, 255, .ScaleHeight - 255
VScroll1.Max = .ScaleHeight + 255 + 255 \ 2
VScroll1.LargeChange = .ScaleHeight / 50
VScroll1.SmallChange = .ScaleHeight / 50
Dim cmdMask As CommandButton
Set cmdMask = Controls.Add("vb.commandbutton", "mask", Picture1)
cmdMask.Move .ScaleWidth - 255, .ScaleHeight - 255, 255, 255
cmdMask.Enabled = False
cmdMask.Visible = True
End With
End SubPrivate Sub HScroll1_Change()
Image1.Left = -HScroll1.Value
End SubPrivate Sub VScroll1_Change()
Image1.Top = -VScroll1.Value
End Sub
Private Sub Command1_Click()
If idx >= 1 Then
idx = idx - 1
Image1.Picture = LoadPicture(File1.Path & "\" & File1.List(idx))End If
End SubPrivate Sub Command2_Click()
If idx < File1.ListCount - 2 Then
idx = idx + 1
Image1.Picture = LoadPicture(File1.Path & "\" & File1.List(idx))
End If
End SubPrivate Sub Dir1_Change()File1.Path = Dir1.Path
File1.Refresh
On Error GoTo chli:
idx = 0
Image1.Picture = LoadPicture(File1.Path & "\" & File1.List(idx))
chli:
Exit Sub
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1.Drive
Dir1.Refresh
End Sub
用楼上的方法,或使用pciturebox控件数组。
2,我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?
使用:PaintPicture方法。对较大图片可以缩小,或只显示局部。
Picture1.PaintPicture Picture,x1,y1,[width1],[height1],[x2],[y2],[width2],[height2],[opcode]
说明:参数Picture为要绘制的图象或加载的图片
x1,y1为图象或图片在控件上的位置,,[width1],[height1为图象或图片在控件上的高度或宽度。[width1],[height1 如果取负值,可以把图象或图片翻转显示。
[x2],[y2]],[width2],[height2]四个参数可以指定只绘制图象或图片的局部。
[opcode]参数指定绘制的方法,建议省略。
Dim fname As String, i As Integer
If Right(mydir, 1) <> "\" Then mydir = mydir & "\"
fname = Dir(mydir & "\*.jpg")
i = 1
Do While fname <> ""
ReDim Preserve x(1 To i)
x(i) = mydir & fname
i = i + 1
fname = Dir
Loop
End SubPrivate Sub Command1_Click()
If index = UBound(alljpgfile) Then
index = 1
Else
index = index + 1
End If
Image1.Picture = LoadPicture(alljpgfile(index))
End SubPrivate Sub Command2_Click()
If index = 1 Then
index = UBound(alljpgfile)
Else
index = index - 1
End If
Image1.Picture = LoadPicture(alljpgfile(index))
End SubPrivate Sub Form_Load()
Command1.Caption = "prev"
Command2.Caption = "next"
index = 1
Image1.Stretch = True
getallfile "C:\Documents and Settings\hsy\My Documents\My Pictures", alljpgfile
Image1.Picture = LoadPicture(alljpgfile(index))
End Sub