'送打开代码 '根据文件路径显示图片 cdgEMP是一个commonDialog控件 Private Sub picEMP_DblClick() Dim strFile As String Dim strFilter As String Dim strArr() As String Dim i As Integer Static strPath As String On Error Resume Next If strPath = "" Then strPath = App.Path cdgEMP.DialogTitle = "选择员工照片" strFilter = "图形文件(*.JPG,*.BMP,*.GIF)|*.JPEG;*.JPG;*.BMP;*.GIF" _ & "|所有文件(*.*)|*.*" cdgEMP.Filter = strFilter cdgEMP.InitDir = strPath cdgEMP.FileName = "" cdgEMP.ShowOpen If Err.Number = cdlCancel Then Exit Sub strFile = cdgEMP.FileName If strFile <> "" Then ' mobjMain.Photo = strFile strArr = Split(strFile, "\", , vbTextCompare) strPath = "" For i = 0 To UBound(strArr) - 1 strPath = strPath & strArr(i) Next i Me.picEMP.Picture = LoadPicture(strFile) End If End Sub
lihonggen0(用VB) and wangsitao(飞猪) 我是用"代码"新建了picturebox(100) 按照你们的,使了一下,不行呀!! 再给我好好看看那!!!!!
dim tag as integer 'tag是一个变量 private sub picturebox_Click(index as integer) for tag=0 to 99 if tag=index then picturebox(tag).属性…… end if next end sub (这段程序应该可以控制了吧,其中“属性”是指你点中的那个控件的属性,“……”表示你要进行的操作)
tag好像不行,那就用其他的变量名吧,如haisland等等
Private Sub picArray_Click(Index As Integer ……) ' Index 即是 控件数组的维数 Select Case Index Case 1 :Msgbox "No1" Case 2 :Msgbox "No2" Case 3 :Msgbox "No3" Case 4 :Msgbox "No4" '……………… End Select End Sub
Option ExplicitPrivate Sub Form_Load() Dim i As Integer For i = 1 To 100 Load Picture1(i) Picture1(i).Top = Picture1(0).Top + 200 * i Picture1(i).Visible = True Next End SubPrivate Sub Picture1_Click(Index As Integer) Picture1(Index).Print "这是第"; Index; "个PictureBox" End Sub
同意楼上的 Private Sub Picture1_Click(Index As Integer) Picture1(Index).Print "这是第"; Index; "个PictureBox."
Select Case Index Case 0: MsgBox "No 0" Case 1: MsgBox "No 1" Case 2: MsgBox "No 2" Case 3: MsgBox "No 3" Case 4: MsgBox "No 4" '……………… End Select
End Sub
private sub picturebox_Click(index as integer) select case index case 0'加入你想在picturebox(0)执行的代码 case 1'同上 …… case else end select end sub 一般情况下,控件数组是用select case来控制的。
Private Sub picArray_Click(Index As Integer ……)
For a=0 to 99 if index=a then msgbox "第" & a & "个" next aEnd Sub
看看我的程序,怎么就是click事件不行呢? Dim Pic(100) As PictureBoxDim iSum, iRow, iCol As Integer Dim iw As Integer Dim iMod As Double isum=1 private sub command1_click() iw = CInt(Picture2.Width / 1500) For iSum = 1 To 5 Set Pic(iSum) = form1.Controls.Add("vb.PictureBox", "Pic" & iSum, Picture1) Pic(iSum).ScaleMode = 1 Pic(iSum).Move iCol * 1500, iRow * 1500 , 1500, 1500 Pic(iSum).Picture = LoadPicture("f:\picture\3.bmp") Pic(iSum).Visible = True iCol = iCol + 1 If (iCol Mod iw = 1) And (iCol > iw) Then iCol = 0 iRow = iRow + 1 End If Next end sub Private Sub Pic_Click(Index As Integer) Select Case Index Case 0: MsgBox "No 0" Case 1: MsgBox "No 1" Case 2: MsgBox "No 2" Case 3: MsgBox "No 3" Case 4: MsgBox "No 4" '……………… End Select End Sub 根本不响应Pic_click事件呀!!!怎么回事????
错了,应该是: 看看我的程序,怎么就是click事件不行呢? Dim Pic(100) As PictureBoxDim iSum, iRow, iCol As Integer Dim iw As Integer Dim iMod As Double isum=1 private sub command1_click() iw = CInt(Picture1.Width / 1500) For iSum = 1 To 5 Set Pic(iSum) = form1.Controls.Add("vb.PictureBox", "Pic" & iSum, Picture1) Pic(iSum).ScaleMode = 1 Pic(iSum).Move iCol * 1500, iRow * 1500 , 1500, 1500 Pic(iSum).Picture = LoadPicture("f:\picture\3.bmp") Pic(iSum).Visible = True iCol = iCol + 1 If (iCol Mod iw = 1) And (iCol > iw) Then iCol = 0 iRow = iRow + 1 End If Next end sub Private Sub Pic_Click(Index As Integer) Select Case Index Case 0: MsgBox "No 0" Case 1: MsgBox "No 1" Case 2: MsgBox "No 2" Case 3: MsgBox "No 3" Case 4: MsgBox "No 4" '……………… End Select End Sub 根本不响应Pic_click事件呀!!!怎么回事????
'根据文件路径显示图片
cdgEMP是一个commonDialog控件
Private Sub picEMP_DblClick()
Dim strFile As String
Dim strFilter As String
Dim strArr() As String
Dim i As Integer
Static strPath As String
On Error Resume Next
If strPath = "" Then strPath = App.Path
cdgEMP.DialogTitle = "选择员工照片"
strFilter = "图形文件(*.JPG,*.BMP,*.GIF)|*.JPEG;*.JPG;*.BMP;*.GIF" _
& "|所有文件(*.*)|*.*"
cdgEMP.Filter = strFilter
cdgEMP.InitDir = strPath
cdgEMP.FileName = ""
cdgEMP.ShowOpen
If Err.Number = cdlCancel Then Exit Sub
strFile = cdgEMP.FileName
If strFile <> "" Then
' mobjMain.Photo = strFile
strArr = Split(strFile, "\", , vbTextCompare)
strPath = ""
For i = 0 To UBound(strArr) - 1
strPath = strPath & strArr(i)
Next i
Me.picEMP.Picture = LoadPicture(strFile)
End If
End Sub
我是用"代码"新建了picturebox(100)
按照你们的,使了一下,不行呀!!
再给我好好看看那!!!!!
private sub picturebox_Click(index as integer)
for tag=0 to 99
if tag=index then
picturebox(tag).属性……
end if
next
end sub
(这段程序应该可以控制了吧,其中“属性”是指你点中的那个控件的属性,“……”表示你要进行的操作)
' Index 即是 控件数组的维数
Select Case Index
Case 1 :Msgbox "No1"
Case 2 :Msgbox "No2"
Case 3 :Msgbox "No3"
Case 4 :Msgbox "No4"
'………………
End Select
End Sub
Dim i As Integer
For i = 1 To 100
Load Picture1(i)
Picture1(i).Top = Picture1(0).Top + 200 * i
Picture1(i).Visible = True
Next
End SubPrivate Sub Picture1_Click(Index As Integer)
Picture1(Index).Print "这是第"; Index; "个PictureBox"
End Sub
Private Sub Picture1_Click(Index As Integer) Picture1(Index).Print "这是第"; Index; "个PictureBox."
Select Case Index
Case 0: MsgBox "No 0"
Case 1: MsgBox "No 1"
Case 2: MsgBox "No 2"
Case 3: MsgBox "No 3"
Case 4: MsgBox "No 4"
'………………
End Select
End Sub
select case index
case 0'加入你想在picturebox(0)执行的代码
case 1'同上
……
case else
end select
end sub
一般情况下,控件数组是用select case来控制的。
For a=0 to 99
if index=a then msgbox "第" & a & "个"
next aEnd Sub
Dim Pic(100) As PictureBoxDim iSum, iRow, iCol As Integer
Dim iw As Integer
Dim iMod As Double
isum=1
private sub command1_click()
iw = CInt(Picture2.Width / 1500)
For iSum = 1 To 5
Set Pic(iSum) = form1.Controls.Add("vb.PictureBox", "Pic" & iSum, Picture1)
Pic(iSum).ScaleMode = 1
Pic(iSum).Move iCol * 1500, iRow * 1500 , 1500, 1500
Pic(iSum).Picture = LoadPicture("f:\picture\3.bmp")
Pic(iSum).Visible = True
iCol = iCol + 1
If (iCol Mod iw = 1) And (iCol > iw) Then
iCol = 0
iRow = iRow + 1
End If
Next
end sub
Private Sub Pic_Click(Index As Integer)
Select Case Index
Case 0: MsgBox "No 0"
Case 1: MsgBox "No 1"
Case 2: MsgBox "No 2"
Case 3: MsgBox "No 3"
Case 4: MsgBox "No 4"
'………………
End Select
End Sub
根本不响应Pic_click事件呀!!!怎么回事????
Dim Pic(100) As PictureBoxDim iSum, iRow, iCol As Integer
Dim iw As Integer
Dim iMod As Double
isum=1
private sub command1_click()
iw = CInt(Picture1.Width / 1500)
For iSum = 1 To 5
Set Pic(iSum) = form1.Controls.Add("vb.PictureBox", "Pic" & iSum, Picture1)
Pic(iSum).ScaleMode = 1
Pic(iSum).Move iCol * 1500, iRow * 1500 , 1500, 1500
Pic(iSum).Picture = LoadPicture("f:\picture\3.bmp")
Pic(iSum).Visible = True
iCol = iCol + 1
If (iCol Mod iw = 1) And (iCol > iw) Then
iCol = 0
iRow = iRow + 1
End If
Next
end sub
Private Sub Pic_Click(Index As Integer)
Select Case Index
Case 0: MsgBox "No 0"
Case 1: MsgBox "No 1"
Case 2: MsgBox "No 2"
Case 3: MsgBox "No 3"
Case 4: MsgBox "No 4"
'………………
End Select
End Sub
根本不响应Pic_click事件呀!!!怎么回事????