DivRem(ByVal a As Integer, ByVal b As Integer, ByRef r As Integer)
Private Sub AjouterPictureBox(ByVal Bmp As Bitmap) Dim pic As New PictureBox, Rang As Integer, x As Integer, y As Integer listpic.Add(pic) : Rang listpic.IndexOf(pic) : y DivRem(Rang, 8, x) With pic .Width = 50 .Height = 50 .Left = 3 + 56 * x .Top = 3 + 56 * y .Image = Bmp End With Panel2.Controls.Add(pic) End Sub
Comme tu vois, il existe tout de même de belles choses en vb.net.
Public Class Form1 Dim screenshot As System.Drawing.Bitmap Private listpic As New List(Of PictureBox) Private Function AddPic() As Boolean Dim pic1 As New PictureBox Try With pic1 pic1.Width = 50 pic1.Height = 50 'placer le pic1 If listpic.Count > 0 Then If listpic(listpic.Count - 1).Right + pic1.Width + 2 > Panel1.Right AndAlso _ listpic(listpic.Count - 1).Bottom < Panel1.Bottom Then 'ajouter le pic1 en début de rangé pic1.Location = New Point(2, listpic(listpic.Count - 1).Bottom + 2) End If If listpic(listpic.Count - 1).Right + pic1.Width + 2 < Panel1.Right AndAlso _ listpic(listpic.Count - 1).Bottom < Panel1.Bottom Then 'ajouter le pic1 à la suite pic1.Location = New Point(listpic(listpic.Count - 1).Right + 2, listpic(listpic.Count - 1).Top) End If Else pic1.Location = New Point(2, 2) End If pic1.SizeMode = PictureBoxSizeMode.StretchImage pic1.BorderStyle = BorderStyle.Fixed3D pic1.Image = screenshot pic1.BringToFront() listpic.Add(pic1) Panel1.Controls.Add(pic1) Return True End With Catch ex As Exception End Try End Function Private Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick Dim bounds As Rectangle Dim graph As Graphics bounds = Screen.PrimaryScreen.Bounds screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb) graph = Graphics.FromImage(screenshot) graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy) If Not AddPic() Then DirectCast(sender, Button).Enabled = False Else DirectCast(sender, Button).Enabled = True End If Dim Save_screen As New SaveFileDialog Try Save_screen.Title = "save file" Save_screen.FileName = "C:\users\user\desktop\screenshoot" & My.Settings.CompteurSave & ".bmp" Save_screen.Filter = "bitmap | *.bmp" listpic(listpic.Count - 1).Image.Save(Save_screen.FileName, System.Drawing.Imaging.ImageFormat.Bmp) My.Settings.CompteurSave = My.Settings.CompteurSave + 1 Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load TabControl1.Width = ClientRectangle.Width - 10 TabControl1.Height = ClientRectangle.Height - Button1.Height - 6 Panel1.Location = New Point(0, 0) Panel1.Width = TabControl1.Width - 10 Panel1.AutoScroll = True Panel1.Height = TabControl1.Height - TabControl1.ItemSize.Height * 2 Button1.Location = New Point(Me.Width \ 2 - Button1.Width \ 2, ClientRectangle.Bottom - Button1.Height - 4) End Sub End Class
Private Sub Command1_Click() Static combien_en_largeur As Integer Static marge As Integer Dim gauche As Integer, haut As Integer If combien_en_largeur = 0 Then reste = Frame1.Width Mod Picture2(0).Width combien_en_largeur = (Frame1.Width - reste) \ Picture2(0).Width marge = reste / (combien_en_largeur + 1) Picture2(0).Left = marge Picture2(0).Top = marge End If gauche = Picture2(Picture2.Count - 1).Left + Picture2(Picture2.Count - 1).Width + marge haut = Picture2(Picture2.Count - 1).Top If gauche + Picture2(0).Width > Frame1.Width Then gauche = marge haut = Picture2(Picture2.Count - 1).Top + Picture2(Picture2.Count - 1).Height + marge End If Load Picture2(Picture2.Count) With Picture2(Picture2.Count - 1) .Visible = True .Left = gauche .Top = haut End With End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Form1 Dim screenshot As System.Drawing.Bitmap Private listpic As New List(Of PictureBox) Private Sub AddPic() Dim pic1 As New PictureBox Try With pic1 pic1.Width = 50 pic1.Height = 50 'placer le pic1 If listpic.Count > 0 Then If listpic(listpic.Count - 1).Right + pic1.Width + 2 > Panel1.Right AndAlso _ listpic(listpic.Count - 1).Bottom < Panel1.Bottom Then 'ajouter le pic1 en début de rangé pic1.Location = New Point(2, listpic(listpic.Count - 1).Bottom + 2) End If If listpic(listpic.Count - 1).Right + pic1.Width + 2 < Panel1.Right AndAlso _ listpic(listpic.Count - 1).Bottom < Panel1.Bottom Then 'ajouter le pic1 à la suite pic1.Location = New Point(listpic(listpic.Count - 1).Right + 2, listpic(listpic.Count - 1).Top) End If Else pic1.Location = New Point(2, 2) End If pic1.SizeMode = PictureBoxSizeMode.StretchImage pic1.BorderStyle = BorderStyle.Fixed3D pic1.Image = screenshot pic1.BringToFront() listpic.Add(pic1) Panel1.Controls.Add(pic1) End With Catch ex As Exception End Try End Sub Private Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick Dim bounds As Rectangle Dim filename As String Dim graph As Graphics Try bounds = Screen.PrimaryScreen.Bounds screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb) graph = Graphics.FromImage(screenshot) graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy) AddPic() filename = "C:\users\user\desktop\screenshoot" & My.Settings.CompteurSave & ".bmp" listpic(listpic.Count - 1).Image.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp) My.Settings.CompteurSave = My.Settings.CompteurSave + 1 My.Settings.Save() Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load TabControl1.Width = ClientRectangle.Width - 10 TabControl1.Height = ClientRectangle.Height - Button1.Height - 6 Panel1.Location = New Point(0, 0) Panel1.Width = TabControl1.Width - 10 Panel1.AutoScroll = True Panel1.Height = TabControl1.Height - TabControl1.ItemSize.Height * 2 Button1.Location = New Point(Me.Width \ 2 - Button1.Width \ 2, ClientRectangle.Bottom - Button1.Height - 4) End Sub End Class
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim savefiledialog1 As New SaveFileDialog Try PictureBox1.Image.Save("C:\Users\Samir\Desktop\Screen_n°" & My.Settings.CompteurSave) Catch ex As Exception End Try Dim bounds As Rectangle Dim screenshot As System.Drawing.Bitmap Dim graph As Graphics bounds = Screen.PrimaryScreen.Bounds screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb) graph = Graphics.FromImage(screenshot) graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy) My.Settings.CompteurSave = My.Settings.CompteurSave + 1 My.Settings.CompteurPict = My.Settings.CompteurPict + 1 If My.Settings.CompteurPict = 65 Then My.Settings.CompteurPict = 1 End If If My.Settings.CompteurPict = 1 Then PictureBox1.Image = screenshot End If If My.Settings.CompteurPict = 2 Then PictureBox2.Image = screenshot End If If My.Settings.CompteurPict = 3 Then PictureBox3.Image = screenshot End If If My.Settings.CompteurPict = 4 Then PictureBox4.Image = screenshot End If 'ETC 'JUSQU'AU PICTUREBOX 64...