public addPictureBox(Point location) { PictureBox m_pic m_pic = new PictureBox(); m_pic.Location = location; form1.Controls.Add(m_pic); }
Public Class Accueil Private WithEvents pBox As New PictureBox Private Sub Accueil_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load pBox.BackColor = Color.Black Me.Controls.Add(pBox) End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim pnj As Bitmap = My.Resources.dirt__2_
e.Graphics.DrawImage(pnj,C ursor.Position.X,C ursor.Position.Y)
'On purge les objets temporaires
pnj.Dispose()
End Sub
Dim pic As PictureBox
Dim x, y, diff, dify, i As Int32
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
pic = New PictureBox()
i += 1
pic.BorderStyle = BorderStyle.Fixed3D
pic.SizeMode = PictureBoxSizeMode.StretchImage
pic.Image = My.Resources.dirt__2_
pic.SetBounds(x, y, 100, 100)
x += 100
'vérifier s'il ya suffisamment d'espace dans l'axe x pour ajouter une image
If x >= Panel1.Width Or (x + 100) > Panel1.Width Then
diff = Panel1.Width - x
'S'il n'y a pas assez d'espace, commencer une nouvelle ligne ci-dessous
y += 100
x = 0
End If
If ((y + 100) > Panel1.Height) Then
dify = Panel1.Height - y
End If
'ajouter une image
Panel1.Controls.Add(pic)
End Sub
Private Structure imagedata
Public thebitmap As Bitmap
Public coords As Point
End Structure
Private listimage As New List(Of imagedata)
'on va remplir listimage avec les images de la resources
' pour faciliter la tache j'ai nommé toutes les images avec le meme
'nom et suffixe 1 2 3 ex im1 im2 im3
Private Sub LoadImage()
Dim imagedt As imagedata
Dim filename As String
Dim x,y As Integer
filename = "im"
x = 10
y = 20
For iter As Integer = 1 To 4
imagedt.thebitmap = CType(My.Resources.ResourceManager.GetObject(filename & iter.ToString), Bitmap)
imagedt.coords = New Point(x, y)
x += imagedt.thebitmap.Width + 6
listimage.Add(imagedt)
Next
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LoadImage()
end sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
For Each item As imagedata In listimage
e.Graphics.DrawImage(item.thebitmap, item.coords)
Next
End Sub
Private Class imagedata
Public thebitmap As Bitmap
Public coords As Point
End Class
Private listimage As New List(Of imagedata)
'on va remplir listimage avec les images de la resources
' pour faciliter la tache j'ai nommé toutes les images avec le meme
'nom et suffixe 1 2 3 ex im1 im2 im3
Private Sub LoadImage()
Dim filename As String
Dim x As Integer
filename = "save"
x = 10
For iter As Integer = 1 To 4
Dim imagedt As New imagedata
imagedt.thebitmap = CType(My.Resources.ResourceManager.GetObject(filename & iter.ToString), Bitmap)
imagedt.coords = New Point(x, 10)
x += imagedt.thebitmap.Width + 6
listimage.Add(imagedt)
Next
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LoadImage()
end sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
For Each item As imagedata In listimage
e.Graphics.DrawImage(item.thebitmap, item.coords)
Next
End Sub
Private Class imagedata
Public thebitmap As Bitmap
Public coords As Point
sub new(file as string, pt as point)
thebitmap = CType(My.Resources.ResourceManager.GetObject(file), Bitmap)
coords = pt
end sub
End Class
listimage.add(New imagedata(filename & iter.tostring, new point(x, 10)))