Public Class clsDigit Inherits PictureBox Sub New(ByVal X As Integer, ByVal Y As Integer, ByVal Image As Image) With Me .Location = New Point(X, Y) .BackColor = Color.Red .Width = 10 .Image = Image ' ..... ainsi de suite End With End Sub End Class
Dim pct1 As New clsDigit(0, 0, CType(My.Resources.image1, Image)) Dim pct2 As New clsDigit(20, 0, CType(My.Resources.image2, Image)) Me.Controls.Add(pct1) Me.Controls.Add(pct2)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Form1 Function ClonePictureBox(ByVal PictureBoxSrc As PictureBox) As PictureBox Dim PictureBoxDst As New PictureBox Dim PictureBoxDstProp As System.Reflection.PropertyInfo() = PictureBoxDst.GetType.GetProperties Dim PictureBoxSrcProp As System.Reflection.PropertyInfo() = PictureBoxSrc.GetType.GetProperties If PictureBoxDstProp.Length <> PictureBoxSrcProp.Length Then MessageBox.Show("Les propriétées entre les deux PictureBox n'ont pas le même nombre de paramètre !", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error) Return Nothing End If For Each SourceProperty As System.Reflection.PropertyInfo In PictureBoxSrc.GetType.GetProperties For Each DestinationProperty As System.Reflection.PropertyInfo In PictureBoxDst.GetType.GetProperties If DestinationProperty.CanWrite = True Then Dim dstOBJ As Object = DestinationProperty.GetValue(PictureBoxDst, Nothing) Dim srcOBJ As Object = SourceProperty.GetValue(PictureBoxSrc, Nothing) If (DestinationProperty.Name SourceProperty.Name) AndAlso (DestinationProperty.PropertyType SourceProperty.PropertyType) Then DestinationProperty.SetValue(PictureBoxDst, srcOBJ, Nothing) Exit For End If End If Next Next Dim gParent As Control = PictureBoxSrc.Parent gParent.Controls.Add(PictureBoxDst) Return PictureBoxDst End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click Dim ChoixBouton As System.Windows.Forms.Button = sender Select Case ChoixBouton.Name Case "Button1" Me.PictureBox1.BackgroundImage = My.Resources.Image_0 Case "Button2" Dim picObjet As PictureBox = ClonePictureBox(PictureBox1) picObjet.BackgroundImage = My.Resources.Image_1 picObjet.Left = PictureBox1.Left + PictureBox1.Width End Select End Sub End Class
Public Class Form1 Class Clone Friend Shared PictureBoxDst As PictureBox Sub New() Clone.PictureBoxDst = New PictureBox End Sub Protected Overrides Sub Finalize() Clone.PictureBoxDst = Nothing MyBase.Finalize() End Sub Friend Shared Function ClonePictureBox(ByVal PictureBoxSrc As PictureBox) As PictureBox Dim PictureBoxDstProp As System.Reflection.PropertyInfo() = Clone.PictureBoxDst.GetType.GetProperties Dim PictureBoxSrcProp As System.Reflection.PropertyInfo() = PictureBoxSrc.GetType.GetProperties If PictureBoxDstProp.Length <> PictureBoxSrcProp.Length Then MessageBox.Show("Les propriétées entre les deux PictureBox n'ont pas le même nombre de paramètre !", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error) Return Nothing End If Dim dstOBJ As Object = Nothing Dim srcOBJ As Object = Nothing For Each SourceProperty As System.Reflection.PropertyInfo In PictureBoxSrcProp For Each DestinationProperty As System.Reflection.PropertyInfo In PictureBoxDstProp If DestinationProperty.CanWrite = True Then dstOBJ = DestinationProperty.GetValue(Clone.PictureBoxDst, Nothing) srcOBJ = SourceProperty.GetValue(PictureBoxSrc, Nothing) If (DestinationProperty.Name SourceProperty.Name) AndAlso (DestinationProperty.PropertyType SourceProperty.PropertyType) Then DestinationProperty.SetValue(Clone.PictureBoxDst, srcOBJ, Nothing) Exit For End If End If Next Next Dim gParent As Control = PictureBoxSrc.Parent gParent.Controls.Add(Clone.PictureBoxDst) Return Clone.PictureBoxDst End Function End Class Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click Dim ChoixBouton As System.Windows.Forms.Button = sender Select Case ChoixBouton.Name Case "Button1" Me.PictureBox1.BackgroundImage = My.Resources.Image_0 Case "Button2" Dim NewClone As New Clone Dim NewPicture As PictureBox = Clone.ClonePictureBox(PictureBox1) Clone.PictureBoxDst.Image = My.Resources.Image_1 Clone.PictureBoxDst.Left = PictureBox1.Left + PictureBox1.Width End Select End Sub End Class
Public Class Form1 Shared Sub ClonePictureBox(ByVal PictureBoxSrc As System.Windows.Forms.PictureBox, ByRef PictureBoxDst As System.Windows.Forms.PictureBox) Dim srcOBJ As Object = Nothing For Each SourceProperty As System.Reflection.PropertyInfo In PictureBoxSrc.GetType.GetProperties For Each DestinationProperty As System.Reflection.PropertyInfo In PictureBoxDst.GetType.GetProperties If DestinationProperty.CanWrite True And DestinationProperty.CanRead True Then If (DestinationProperty.Name SourceProperty.Name) And (DestinationProperty.PropertyType SourceProperty.PropertyType) Then srcOBJ = SourceProperty.GetValue(PictureBoxSrc, Nothing) DestinationProperty.SetValue(PictureBoxDst, srcOBJ, Nothing) Exit For End If End If Next Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click Dim ChoixBouton As System.Windows.Forms.Button = sender Select Case ChoixBouton.Name Case "Button1" Me.PictureBox1.BackgroundImage = My.Resources.Image_0 Case "Button2" Dim NewPicture As New System.Windows.Forms.PictureBox ClonePictureBox(Me.PictureBox1, NewPicture) NewPicture = DirectCast(NewPicture, PictureBox) NewPicture.BackgroundImage = My.Resources.Image_1 NewPicture.Left = PictureBox1.Left + PictureBox1.Width End Select End Sub End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim CompteurIndex As New List(Of Integer) Dim CompteurMax As Integer = 6 '999999 Dim DecalLeft As Integer = 507 Dim DecalTop As Integer = 135 For i As Integer = CompteurMax To 1 Step -1 CompteurIndex.Add(DecalLeft) DecalLeft -= 15 Next Dim pct1 As New clsDigit(My.Resources.Compteur_0, CompteurIndex.Item(0), DecalTop) 'xxxxx0 Dim pct2 As New clsDigit(My.Resources.Compteur_1, CompteurIndex.Item(1), DecalTop) 'xxxx10 Me.Controls.Add(pct1) Me.Controls.Add(pct2) End Sub Public Class clsDigit Inherits PictureBox Sub New(ByVal ThisCounterImage As Bitmap, ByVal DecalLeft As Integer, ByVal DecalTop As Integer) Dim CounterImageConv As Image = CType(ThisCounterImage, Image) With Me .Visible = False .Width = ThisCounterImage.Width .Height = ThisCounterImage.Height .Location = New Point(DecalLeft, DecalTop) .BackColor = Color.Transparent .BackgroundImage = CounterImageConv .BackgroundImageLayout = ImageLayout.None .Left = DecalLeft .Visible = True End With End Sub End Class