Questo topic e' stato chiuso dal moderatore.
25/06/08 13:24
mayoita
Salve a tutti,
vi espongo subito il mio problema. Ho caricato delle immagini jpg in delle PictureBox da codice ma non riesco ad associare ad ogni singola PictureBox l'evento Click. qualcuno sa dirmi come riuscirci?
Allego il codice per maggiore chiarezza.
Grazie.
Public Class Form1
Dim picturebox1 As PictureBox
Dim ListView1 As ListView
Dim a As Image
Private Sub InitializePictureBox()
Dim i As Integer = 0
Dim n As Integer = 1
Dim y As Integer = 100
Dim yn As Integer = 0
Const distanzaVerticaleTraImmagini = 150
Const distanzaDaBordoIniziale = 20
Dim dirInfo As New System.IO.DirectoryInfo("c:\cinemaimg"
Dim file As System.IO.FileInfo
Dim SpazioTraImmagini As Integer = 120
Dim files() As System.IO.FileInfo = dirInfo.GetFiles("*.jpg"
If Not (files Is Nothing) Then
For Each file In files
picturebox1 = New PictureBox
If n = 16 Then
n = 1
y = y + distanzaVerticaleTraImmagini
i = 0
Else
n = n + 1
End If
Me.picturebox1.Location = New System.Drawing.Point(distanzaDaBordoIniziale + (SpazioTraImmagini * i), y)
i = i + 1
Me.picturebox1.Size = New System.Drawing.Size(100, 120)
Me.picturebox1.Image = System.Drawing.Image.FromFile _
(file.FullName)
Me.picturebox1.TabStop = False
Me.picturebox1.SizeMode = PictureBoxSizeMode.StretchImage
Me.picturebox1.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(Me.picturebox1)
Next
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
InitializePictureBox()
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim value As Point
Dim r As Integer = 0
value = Control.MousePosition
Do Until value.X > 0
If r = Me.Controls.Count Then
r = 0
Else : picturebox1 = Me.Controls(r)
r = r + 1
If picturebox1.Location.X = -101 Then
Me.picturebox1.Location = New System.Drawing.Point(1700, Me.picturebox1.Location.Y)
Me.Refresh()
End If
Me.picturebox1.Location = New System.Drawing.Point(Me.picturebox1.Location.X - 1, Me.picturebox1.Location.Y)
End If
value = Control.MousePosition
Loop
Do Until value.X < 1260
If r = Me.Controls.Count Then
r = 0
Else : picturebox1 = Me.Controls(r)
r = r + 1
If picturebox1.Location.X = 1700 Then
Me.picturebox1.Location = New System.Drawing.Point(-100, Me.picturebox1.Location.Y)
Me.Refresh()
End If
Me.picturebox1.Location = New System.Drawing.Point(Me.picturebox1.Location.X + 1, Me.picturebox1.Location.Y)
End If
value = Control.MousePosition
Loop
End Sub
End Class
vi espongo subito il mio problema. Ho caricato delle immagini jpg in delle PictureBox da codice ma non riesco ad associare ad ogni singola PictureBox l'evento Click. qualcuno sa dirmi come riuscirci?
Allego il codice per maggiore chiarezza.
Grazie.
Public Class Form1
Dim picturebox1 As PictureBox
Dim ListView1 As ListView
Dim a As Image
Private Sub InitializePictureBox()
Dim i As Integer = 0
Dim n As Integer = 1
Dim y As Integer = 100
Dim yn As Integer = 0
Const distanzaVerticaleTraImmagini = 150
Const distanzaDaBordoIniziale = 20
Dim dirInfo As New System.IO.DirectoryInfo("c:\cinemaimg"
Dim file As System.IO.FileInfo
Dim SpazioTraImmagini As Integer = 120
Dim files() As System.IO.FileInfo = dirInfo.GetFiles("*.jpg"
If Not (files Is Nothing) Then
For Each file In files
picturebox1 = New PictureBox
If n = 16 Then
n = 1
y = y + distanzaVerticaleTraImmagini
i = 0
Else
n = n + 1
End If
Me.picturebox1.Location = New System.Drawing.Point(distanzaDaBordoIniziale + (SpazioTraImmagini * i), y)
i = i + 1
Me.picturebox1.Size = New System.Drawing.Size(100, 120)
Me.picturebox1.Image = System.Drawing.Image.FromFile _
(file.FullName)
Me.picturebox1.TabStop = False
Me.picturebox1.SizeMode = PictureBoxSizeMode.StretchImage
Me.picturebox1.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(Me.picturebox1)
Next
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
InitializePictureBox()
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim value As Point
Dim r As Integer = 0
value = Control.MousePosition
Do Until value.X > 0
If r = Me.Controls.Count Then
r = 0
Else : picturebox1 = Me.Controls(r)
r = r + 1
If picturebox1.Location.X = -101 Then
Me.picturebox1.Location = New System.Drawing.Point(1700, Me.picturebox1.Location.Y)
Me.Refresh()
End If
Me.picturebox1.Location = New System.Drawing.Point(Me.picturebox1.Location.X - 1, Me.picturebox1.Location.Y)
End If
value = Control.MousePosition
Loop
Do Until value.X < 1260
If r = Me.Controls.Count Then
r = 0
Else : picturebox1 = Me.Controls(r)
r = r + 1
If picturebox1.Location.X = 1700 Then
Me.picturebox1.Location = New System.Drawing.Point(-100, Me.picturebox1.Location.Y)
Me.Refresh()
End If
Me.picturebox1.Location = New System.Drawing.Point(Me.picturebox1.Location.X + 1, Me.picturebox1.Location.Y)
End If
value = Control.MousePosition
Loop
End Sub
End Class
aaa