Public Class Form1 Private xp, yp As Integer Private lastmouselocation As New Point Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk Dim mypic As New PictureBox With mypic .Image = Image.FromFile(OpenFileDialog1.FileName) .Width = .Image.Width .Height = .Image.Height .Location = New Point(xp, yp) xp += .Width If xp > Panel1.Width Then xp = 1 yp += .Height If yp > Panel1.Height Then MessageBox.Show("your panel is full") Exit Sub End If End If AddHandler mypic.MouseMove, AddressOf mypicmousemove AddHandler mypic.MouseDown, AddressOf mypicMouseDown End With ' listpic.Add(mypic) Panel1.Controls.Add(mypic) End Sub Private Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick OpenFileDialog1.ShowDialog() End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load xp = 1 yp = 1 Button1.Location = New Point(1, 1) Panel1.Location = New Point(10, Button1.Bottom + 1) Panel1.Width = ClientRectangle.Width - 20 Panel1.Height = Me.Height - Button1.Height End Sub Private Sub mypicmousemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Dim pt As New Point pt = e.Location If e.Button = Windows.Forms.MouseButtons.Left Then pt.X = (pt.X + DirectCast(sender, PictureBox).Left) - lastmouselocation.X pt.Y = (pt.Y + DirectCast(sender, PictureBox).Top) - lastmouselocation.Y DirectCast(sender, PictureBox).Location = pt DirectCast(sender, PictureBox).BringToFront() End If End Sub Private Sub mypicMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) lastmouselocation = e.Location End Sub End Class
Je ne veux pas sortir de ma Form ou de mon Panel.
Private Sub lbLabelMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Dim pt As New Point pt = e.Location If e.Button = Windows.Forms.MouseButtons.Left Then pt.X = (pt.X + DirectCast(sender, label).Left) - lastmouselocation.X pt.Y = (pt.Y + DirectCast(sender, label).Top) - lastmouselocation.Y If pt.X < 0 Then pt.X = 0 End If If pt.Y < 0 Then pt.Y = 0 End If If pt.X > Panel1.Width - DirectCast(sender, label).Width Then pt.X = Panel1.Width - DirectCast(sender, label).Width End If If pt.Y > Panel1.Height - DirectCast(sender, label).Height Then pt.Y = Panel1.Height - DirectCast(sender, label).Height End If DirectCast(sender, label).Location = pt end sub
imgPicture.Image(counter)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionprivate mesimages as new list(of picturebox) Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk Dim mypic As New PictureBox With mypic 'tout le reste End with mesimages.add(mypic) end sub
#Region "Moving Controls" Private Sub lbLabelMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Dim pt As New Point pt = e.Location If e.Button = Windows.Forms.MouseButtons.Left Then If pt.X < 0 Then Beep() End If pt.X = (pt.X + MyLabel.Left) - lastMouseLocation.X pt.Y = (pt.Y + MyLabel.Top) - lastMouseLocation.Y MyLabel.Location = pt MyLabel.BringToFront() Me.XLabel.Text = CStr(pt.X) Me.YLabel.Text = CStr(pt.Y) End If End Sub Private Sub imgPictureMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Dim pt As New Point pt = e.Location If e.Button = Windows.Forms.MouseButtons.Left Then pt.X = (pt.X + DirectCast(sender, PictureBox).Left) - lastMouseLocation.X pt.Y = (pt.Y + DirectCast(sender, PictureBox).Top) - lastMouseLocation.Y DirectCast(sender, PictureBox).Location = pt DirectCast(sender, PictureBox).BringToFront() End If End Sub Private Sub objObjectMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) ' Move objets Label and PictureBox lastMouseLocation = e.Location End Sub #End Region
Merci pour cette derniere precision, ce sera une base a creuser.
Le probleme principal quand je fais un petit software, c'est que je le cree au fur et a mesure
Me.XLabel.Text = CStr(pt.X)
If pt.X < 0 Then Beep() End If
If pt.X < 0 Then pt.X = 0 End If
'...code... If pt.X < 0 Then pt.X = 0 End If pt.X = (pt.X + DirectCast(sender, label).Left) - lastmouselocation.X pt.Y = (pt.Y + DirectCast(sender, label).Top) - lastmouselocation.Y '...code...
'...code... pt.X = (pt.X + DirectCast(sender, label).Left) - lastmouselocation.X pt.Y = (pt.Y + DirectCast(sender, label).Top) - lastmouselocation.Y If pt.X < 0 Then pt.X = 0 End If '...code...