Private Sub WidthTrackBar_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles WidthTrackBar.Scroll Dim pict As Control Dim img As PictureBox For Each pict In Me.Controls If TypeOf pict Is PictureBox Then img = CType(pict, PictureBox) If img.BorderStyle = BorderStyle.Fixed3D Then If (img.Width + img.Left) < Me.Width Then ' img.Width + img.Left = img.Right img.Width = WidthTrackBar.Value Else WidthTrackBar.Value = img.Width End If End If End If Next WidthTextBox.Text = WidthTrackBar.Value.ToString End Sub
Call PictureMouseMove(img, Nothing)
Private Sub imgPictureMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Dim pt As New Point pt = e.Location '...code...
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub WidthTrackBar_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll For Each pict In me.Controls If TypeOf pict Is PictureBox Then If DirectCast(pict, PictureBox).BorderStyle = BorderStyle.Fixed3D Then DirectCast(pict, PictureBox).Width = DirectCast(sender, TrackBar).Value Call PictureMouseMove(DirectCast(pict, PictureBox), CType(e, MouseEventArgs)) End If End If Next WidthTextBox.Text = WidthTrackBar.Value.ToString End Sub
Call PictureMouseMove(DirectCast(pict, PictureBox), CType(e, MouseEventArgs))
Call PictureMouseMove(DirectCast(pict, PictureBox), lastMouseLocation)
img.Width = WidthTrackBar.Value
img.Width += WidthTrackBar.Value
Public Class Form1 Private xp, yp As Integer Private thescrollwidth As Integer Private listpic As New List(Of PictureBox) 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 .BackgroundImage = Image.FromFile(OpenFileDialog1.FileName) .BackgroundImageLayout = ImageLayout.Stretch .Location = New Point(xp, yp) .BorderStyle = BorderStyle.Fixed3D .Width = .BackgroundImage.Width .Height = .BackgroundImage.Height xp += .Width If xp > Me.Width Then xp = 1 yp += .Height If yp > Me.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) Me.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) Me.Location = New Point(10, Button1.Bottom + 1) TrackBar1.Left = Me.Width \ 2 - TrackBar1.Width \ 2 TrackBar1.Top = Me.Bottom - 2 * TrackBar1.Height thescrollwidth = TrackBar1.Maximum 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 If pt.X < 0 Then pt.X = 0 End If If pt.Y < 0 Then pt.Y = 0 End If If pt.X > Me.Width - DirectCast(sender, PictureBox).Width Then pt.X = Me.Width - DirectCast(sender, PictureBox).Width End If If pt.Y > Me.Height - DirectCast(sender, PictureBox).Height Then pt.Y = Me.Height - DirectCast(sender, PictureBox).Height End If 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 Private Sub TrackBar1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll Dim widthpic As Integer For Each pict In Me.Controls If TypeOf pict Is PictureBox Then If DirectCast(pict, PictureBox).BorderStyle = BorderStyle.Fixed3D Then 'on saisi la width de l'image If thescrollwidth < DirectCast(sender, TrackBar).Value Then thescrollwidth = DirectCast(sender, TrackBar).Value widthpic = DirectCast(pict, PictureBox).Width + DirectCast(sender, TrackBar).Value Else thescrollwidth = DirectCast(sender, TrackBar).Value widthpic = DirectCast(pict, PictureBox).Width - DirectCast(sender, TrackBar).Value End If If widthpic < Me.Width Then DirectCast(pict, PictureBox).Width = widthpic End If End If End If Next End Sub End Class
AddHandler myPicture.MouseMove, AddressOf PictureMouseMove
If (img.Width + img.Left) < Me.Width Then ' img.Width + img.Left = img.Right img.Width WidthTrackBar.Value