IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

Dupliquer deux windows form imbriqués


Sujet :

Windows Forms

  1. #1
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Juin 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2013
    Messages : 5
    Points : 4
    Points
    4
    Par défaut Dupliquer deux windows form imbriqués
    Bonjour à tous,

    Description du fonctionnement du projet (car il fonctionne lol):
    C'est un petit logiciel de gestion des raccourcis de dossiers/fichiers. On peut ajouter des dossiers ou des fichiers par drag and drop.

    J'ai deux windows form: form1 et form3.
    Le form1 est inclus dans le form3 (AddOwnedForm). Ceci pour permettre de créer un effet de semi-transparence (form3 est réglé sur opacity à 75% et form1 est transparent grâce à transparencykey ).
    Pour compliquer la tâche, j'ai supprimé les bordures sur les form, du coup j'ai du implémenter, comme j'ai pu voir sur youtu*e, des petites barres invisibles pour pouvoir redimensionner tout ça.
    Enfin on peut déplacer les form à partir de n'importe quel point.

    Mon besoin:
    Créer un bouton qui permette à l'utilisateur de dupliquer la même fenêtre pour en créer d'autres (pour mettre d'autres raccourcis).

    Voici mon soucis:
    Pour que tout ceci fonctionne, les deux form s'appellent dans le code. Dans le code de form1, form3 est cité. Dans le code de form3, form1 est cité.
    Du coup, si je fais (en utilisant "aaa" comme nom par exemple):
    et
    Et bien ça ne peut pas fonctionner parce qu'ils ne se nomment plus pareil (le code cherche les form1 et form3).
    Je ne sais pas si c'est vraiment très clair, mais je coince vraiment...

    Voici les deux codes, des deux formulaires dans leur intégralité:
    Form3:
    Code vb.net : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    Public Class Form3
     
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     
            Me.Label1.Text = "fenêtre 1"
     
            Me.AddOwnedForm(Form1)
            Form1.Show()
     
        End Sub
     
        Private Sub AlignForms(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged, Me.Move, Me.Layout
     
            Form1.Location = New Point(Me.Location.X + 2, Me.Location.Y + 2)
            Form1.Width = Me.ClientSize.Width - 4
            Form1.Height = Me.ClientSize.Height - 4
     
     
        End Sub
     
     
        Private Sub upR_MouseMove(sender As Object, e As MouseEventArgs) Handles upR.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Size = New Size(Me.Size.Width, Me.Size.Height + (Me.Location.Y - MousePosition.Y))
                Me.Location = New Point(Me.Location.X, MousePosition.Y)
            End If
        End Sub
     
     
     
        Private Sub Form3_Resize(sender As Object, e As EventArgs) Handles Me.Resize
            downR.Location = New Point(0, Me.Size.Height - 2)
            rightR.Location = New Point(Me.Size.Width - 2, 0)
            upR.Size = New Size(Me.Size.Width, 2)
            downR.Size = New Size(Me.Size.Width, 2)
            leftR.Size = New Size(2, Me.Size.Height)
            rightR.Size = New Size(2, Me.Size.Height)
     
            Label1.Location = New Point(Me.Size.Width / 2 - 30, 0)
            PictureBox1.Size = New Size(Me.Size.Width, 1)
     
            'My.Settings.collection1.Item(0)
     
            Form1.Button1.Location = New Point(Form1.Button1.Location.X, Me.Size.Height - 30)
            Form1.Button2.Location = New Point(Form1.Button2.Location.X, Me.Size.Height - 30)
            Form1.Button3.Location = New Point(Form1.Button3.Location.X, Me.Size.Height - 30)
            Form1.Button4.Location = New Point(Form1.Button4.Location.X, Me.Size.Height - 30)
     
            On Error Resume Next
            Form1.Location = New Point(Me.Location.X + 2, Me.Location.X + 2)
            Form1.Width = Me.ClientSize.Width - 4
            Form1.Height = Me.ClientSize.Width - 4
     
        End Sub
     
        Private Sub rightR_MouseMove(sender As Object, e As MouseEventArgs) Handles rightR.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Size = New Size(MousePosition.X - Me.Location.X, Me.Size.Height)
            End If
        End Sub
     
     
        Private Sub leftR_MouseMove(sender As Object, e As MouseEventArgs) Handles leftR.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Size = New Size(Me.Size.Width + (Me.Location.X - MousePosition.X), Me.Size.Height)
                Me.Location = New Point(MousePosition.X, Me.Location.Y)
     
            End If
        End Sub
     
        Private Sub downR_MouseMove(sender As Object, e As MouseEventArgs) Handles downR.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Size = New Size(Me.Size.Width, MousePosition.Y - Me.Location.Y)
            End If
        End Sub
    End Class

    form1:
    Code vb.net : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    Public Class Form1
        'Inherits System.Windows.Forms.Form
     
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     
     
            Me.AllowDrop = True
     
     
            If My.Settings.collection1.Count > 1 Then
                'My.Settings.Reset()
                For Each i In My.Settings.collection1
                    If Not i = "a" Then
                        Dim MyButton = New Button
                        MyButton.Text = My.Computer.FileSystem.GetName(i)
                        MyButton.AccessibleDescription = i
                        MyButton.Height = 125
     
                        Dim fileNames = My.Computer.FileSystem.GetName(i)
                        Dim isExtension As String = Mid(Mid(fileNames, Len(fileNames) - 3), 1)
     
     
                        If isExtension = ".xls" Or isExtension = "xlsx" Then
                            MyButton.BackgroundImage = My.Resources.Logo_Microsoft_Excel_2013
                        ElseIf isExtension = ".doc" Or isExtension = "docx" Then
                            MyButton.BackgroundImage = My.Resources.Logo_Microsoft_Word_2013
                        ElseIf isExtension = ".pdf" Then
                            MyButton.BackgroundImage = My.Resources.logo_pdf
                        ElseIf InStr(isExtension, ".") > 0 Then
                            MyButton.BackgroundImage = My.Resources.FileLogo_TextFile
                        Else
                            MyButton.BackgroundImage = My.Resources.folder_256
                        End If
     
     
                        MyButton.BackgroundImageLayout = ImageLayout.None
                        MyButton.BackColor = Color.White
                        MyButton.TextAlign = ContentAlignment.BottomCenter
     
                        Me.FlowLayoutPanel1.Controls.Add(MyButton)
     
                        AddHandler MyButton.Click, AddressOf Me.Button
     
                    End If
                Next
     
            End If
     
     
     
     
     
     
        End Sub
     
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
            ' fichierTexte.Dispose()
        End Sub
     
        Private Sub Button(ByVal sender As System.Object, ByVal e As System.EventArgs)
            On Error Resume Next
            Process.Start(CType(CType(sender, System.Windows.Forms.Button).AccessibleDescription, String))
        End Sub
     
     
        Private Sub Form1_DragDrop(sender As Object, e As DragEventArgs) Handles MyBase.DragDrop
     
     
     
            Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
            For Each path In files
     
                Dim fileNames = My.Computer.FileSystem.GetName(path)
     
                Dim isExtension As String = Mid(Mid(fileNames, Len(fileNames) - 3), 1)
     
     
     
                My.Settings.collection1.Add(path)
     
     
     
                Dim button1 As New Button
                button1.Text = fileNames
                button1.AccessibleDescription = path
                button1.Height = 125
     
     
                If isExtension = ".xls" Or isExtension = "xlsx" Then
                    button1.BackgroundImage = My.Resources.Logo_Microsoft_Excel_2013
                ElseIf isExtension = ".doc" Or isExtension = "docx" Then
                    button1.BackgroundImage = My.Resources.Logo_Microsoft_Word_2013
                ElseIf isExtension = ".pdf" Then
                    button1.BackgroundImage = My.Resources.logo_pdf
                ElseIf InStr(isExtension, ".") > 0 Then
                    button1.BackgroundImage = My.Resources.FileLogo_TextFile
                Else
                    button1.BackgroundImage = My.Resources.folder_256
                End If
     
                button1.BackgroundImageLayout = ImageLayout.None
                button1.BackColor = Color.White
                button1.TextAlign = ContentAlignment.BottomCenter
     
                Me.FlowLayoutPanel1.Controls.Add(button1)
                AddHandler button1.Click, AddressOf Me.Button
     
     
            Next
     
     
     
        End Sub
     
     
        Private Sub Form1_DragEnter(sender As Object, e As DragEventArgs) Handles MyBase.DragEnter
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                e.Effect = DragDropEffects.Copy
            End If
        End Sub
     
     
        Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
            Me.FlowLayoutPanel1.Width = Me.Width - 5
            Me.FlowLayoutPanel1.Height = Me.Height - 35
            Me.FlowLayoutPanel1.Refresh()
     
     
     
            'Me.Button1.Left = Me.Width / 2 - 46
            'Me.Button1.Top = Me.Height - 80
     
        End Sub
     
     
     
        'Private Sub Button2_Click(sender As Object, e As EventArgs)
        '    On Error Resume Next
        '    Process.Start(Me.Button2.AccessibleDescription)
        'End Sub
     
        Public Sub New()
     
            ' Cet appel est requis par le concepteur.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
     
        End Sub
     
     
     
     
        Private Sub Button1_Click(sender As Object, e As EventArgs)
     
     
            My.Settings.collection1.Clear()
            My.Settings.collection1.Add("a")
            Me.FlowLayoutPanel1.Controls.Clear()
     
        End Sub
     
        Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
     
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Form3.Left = MousePosition.X - mousex
                Form3.Top = MousePosition.Y - mousey
                'Me.Location = New Point(MousePosition.X, MousePosition.Y)
     
     
            End If
     
        End Sub
     
        Dim mousex As Integer
        Dim mousey As Integer
        Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
            mousex = Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable mousex
            mousey = Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable 
        End Sub
     
        Private Sub FlowLayoutPanel1_MouseDown(sender As Object, e As MouseEventArgs) Handles FlowLayoutPanel1.MouseDown
            mousex = Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable mousex
            mousey = Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable 
        End Sub
     
        Private Sub FlowLayoutPanel1_MouseMove(sender As Object, e As MouseEventArgs) Handles FlowLayoutPanel1.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Form3.Left = MousePosition.X - mousex
                Form3.Top = MousePosition.Y - mousey
                'Me.Location = New Point(MousePosition.X, MousePosition.Y)
     
     
            End If
        End Sub
     
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
     
            Dim nom As String
            nom = InputBox("Veuillez indiquer le nom de la fenêtre", "Nom de la fenêtre")
     
            Form3.Label1.Text = nom
     
        End Sub
     
        Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
     
            If ColorDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
                Form3.BackColor = ColorDialog1.Color
     
            End If
     
        End Sub
     
     
     
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
     
        End Sub
    End Class

    Pourriez-vous m'aiguiller?
    Merci bien.
    Nico.

  2. #2
    Membre habitué
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2012
    Messages
    80
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Juin 2012
    Messages : 80
    Points : 163
    Points
    163
    Par défaut
    Je comprends mal où est ton problème. Qu'est ce qui ne marche pas?

    Tu devrai créer un constructeur comme celui-ci. ça ne résout pas le problème (je ne l'ai pas compris mais ce sera plus propre)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
     
    Public sub new(byref pForm as Form)
            Me.AddOwnedForm(pForm)
     
    addhandler me.Load, sub(o, e)
                                        pForm.show()
                                end sub
    end sub

  3. #3
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Juin 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2013
    Messages : 5
    Points : 4
    Points
    4
    Par défaut
    Bonjour et merci pour ton aide!

    Ce qui ne marche pas, par exemple, c'est ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     Form1.Location = New Point(Me.Location.X + 2, Me.Location.Y + 2)
            Form1.Width = Me.ClientSize.Width - 4
            Form1.Height = Me.ClientSize.Height - 4
    Ce bout de code se situe dans form3. On y site explicitement form1. Mais si je créé un bouton pour dupliquer l'ensemble (form1 et form3), le code s'appliquera toujours à form1 et pas sa copie...

    J'ai essayé de faire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Me.OwnedForms(0).Location = New Point(Me.Location.X + 2, Me.Location.Y + 2)
            Me.OwnedForms(0).Width = Me.ClientSize.Width - 4
            Me.OwnedForms(0).Height = Me.ClientSize.Height - 4
    Mais ça ne marche pas, ça me sort une erreur parce que "Me.AddOwnedForm(Form1)" se trouve dans load du form3 et que je veux y accéder ailleurs.
    J'ai donc tout mis en public pour voir, mais ça met quand même "xxx n'est pas déclaré, il est peut être inaccessible en raison de son niveau de protection...

    Je suis vraiment bloqué du coup ^^'

  4. #4
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Juin 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2013
    Messages : 5
    Points : 4
    Points
    4
    Par défaut
    Wow, je suis trop content j'ai trouvé....

    Bon, si quelqu'un butte au même endroit que moi, voici ma solution:
    form3:
    Code vb.net : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    Public Class Form3
     
        Public aa As New Form1
     
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     
            Me.Label1.Text = "fenêtre 1"
     
            Me.AddOwnedForm(aa)
            aa.Show()
     
     
     
        End Sub
     
        Private Sub AlignForms(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged, Me.Move, Me.Layout
     
            aa.Location = New Point(Me.Location.X + 2, Me.Location.Y + 2)
            aa.Width = Me.ClientSize.Width - 4
            aa.Height = Me.ClientSize.Height - 4
     
     
        End Sub
     
     
        Private Sub upR_MouseMove(sender As Object, e As MouseEventArgs) Handles upR.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Size = New Size(Me.Size.Width, Me.Size.Height + (Me.Location.Y - MousePosition.Y))
                Me.Location = New Point(Me.Location.X, MousePosition.Y)
            End If
        End Sub
     
     
     
        Private Sub Form3_Resize(sender As Object, e As EventArgs) Handles Me.Resize
            downR.Location = New Point(0, Me.Size.Height - 2)
            rightR.Location = New Point(Me.Size.Width - 2, 0)
            upR.Size = New Size(Me.Size.Width, 2)
            downR.Size = New Size(Me.Size.Width, 2)
            leftR.Size = New Size(2, Me.Size.Height)
            rightR.Size = New Size(2, Me.Size.Height)
     
            Label1.Location = New Point(Me.Size.Width / 2 - 30, 0)
            PictureBox1.Size = New Size(Me.Size.Width, 1)
     
            'My.Settings.collection1.Item(0)
     
            aa.Button1.Location = New Point(aa.Button1.Location.X, Me.Size.Height - 30)
            aa.Button2.Location = New Point(aa.Button2.Location.X, Me.Size.Height - 30)
            aa.Button3.Location = New Point(aa.Button3.Location.X, Me.Size.Height - 30)
            aa.Button4.Location = New Point(aa.Button4.Location.X, Me.Size.Height - 30)
     
            On Error Resume Next
            aa.Location = New Point(Me.Location.X + 2, Me.Location.X + 2)
            aa.Width = Me.ClientSize.Width - 4
            aa.Height = Me.ClientSize.Width - 4
     
        End Sub
     
        Private Sub rightR_MouseMove(sender As Object, e As MouseEventArgs) Handles rightR.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Size = New Size(MousePosition.X - Me.Location.X, Me.Size.Height)
            End If
        End Sub
     
     
        Private Sub leftR_MouseMove(sender As Object, e As MouseEventArgs) Handles leftR.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Size = New Size(Me.Size.Width + (Me.Location.X - MousePosition.X), Me.Size.Height)
                Me.Location = New Point(MousePosition.X, Me.Location.Y)
     
            End If
        End Sub
     
        Private Sub downR_MouseMove(sender As Object, e As MouseEventArgs) Handles downR.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Size = New Size(Me.Size.Width, MousePosition.Y - Me.Location.Y)
            End If
        End Sub
     
     
     
    End Class
    form1:
    Code vb.net : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    Public Class Form1
        'Inherits System.Windows.Forms.Form
     
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     
     
            Me.AllowDrop = True
     
     
            If My.Settings.collection1.Count > 1 Then
                'My.Settings.Reset()
                For Each i In My.Settings.collection1
                    If Not i = "a" Then
                        Dim MyButton = New Button
                        MyButton.Text = My.Computer.FileSystem.GetName(i)
                        MyButton.AccessibleDescription = i
                        MyButton.Height = 125
     
                        Dim fileNames = My.Computer.FileSystem.GetName(i)
                        Dim isExtension As String = Mid(Mid(fileNames, Len(fileNames) - 3), 1)
     
     
                        If isExtension = ".xls" Or isExtension = "xlsx" Then
                            MyButton.BackgroundImage = My.Resources.Logo_Microsoft_Excel_2013
                        ElseIf isExtension = ".doc" Or isExtension = "docx" Then
                            MyButton.BackgroundImage = My.Resources.Logo_Microsoft_Word_2013
                        ElseIf isExtension = ".pdf" Then
                            MyButton.BackgroundImage = My.Resources.logo_pdf
                        ElseIf InStr(isExtension, ".") > 0 Then
                            MyButton.BackgroundImage = My.Resources.FileLogo_TextFile
                        Else
                            MyButton.BackgroundImage = My.Resources.folder_256
                        End If
     
     
                        MyButton.BackgroundImageLayout = ImageLayout.None
                        MyButton.BackColor = Color.White
                        MyButton.TextAlign = ContentAlignment.BottomCenter
     
                        Me.FlowLayoutPanel1.Controls.Add(MyButton)
     
                        AddHandler MyButton.Click, AddressOf Me.Button
     
                    End If
                Next
     
            End If
     
     
     
     
     
     
        End Sub
     
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
            ' fichierTexte.Dispose()
        End Sub
     
        Private Sub Button(ByVal sender As System.Object, ByVal e As System.EventArgs)
            On Error Resume Next
            Process.Start(CType(CType(sender, System.Windows.Forms.Button).AccessibleDescription, String))
        End Sub
     
     
        Private Sub Form1_DragDrop(sender As Object, e As DragEventArgs) Handles MyBase.DragDrop
     
     
     
            Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
            For Each path In files
     
                Dim fileNames = My.Computer.FileSystem.GetName(path)
     
                Dim isExtension As String = Mid(Mid(fileNames, Len(fileNames) - 3), 1)
     
     
     
                My.Settings.collection1.Add(path)
     
     
     
                Dim button1 As New Button
                button1.Text = fileNames
                button1.AccessibleDescription = path
                button1.Height = 125
     
     
                If isExtension = ".xls" Or isExtension = "xlsx" Then
                    button1.BackgroundImage = My.Resources.Logo_Microsoft_Excel_2013
                ElseIf isExtension = ".doc" Or isExtension = "docx" Then
                    button1.BackgroundImage = My.Resources.Logo_Microsoft_Word_2013
                ElseIf isExtension = ".pdf" Then
                    button1.BackgroundImage = My.Resources.logo_pdf
                ElseIf InStr(isExtension, ".") > 0 Then
                    button1.BackgroundImage = My.Resources.FileLogo_TextFile
                Else
                    button1.BackgroundImage = My.Resources.folder_256
                End If
     
                button1.BackgroundImageLayout = ImageLayout.None
                button1.BackColor = Color.White
                button1.TextAlign = ContentAlignment.BottomCenter
     
                Me.FlowLayoutPanel1.Controls.Add(button1)
                AddHandler button1.Click, AddressOf Me.Button
     
     
            Next
     
     
     
        End Sub
     
     
        Private Sub Form1_DragEnter(sender As Object, e As DragEventArgs) Handles MyBase.DragEnter
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                e.Effect = DragDropEffects.Copy
            End If
        End Sub
     
     
        Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
            Me.FlowLayoutPanel1.Width = Me.Width - 5
            Me.FlowLayoutPanel1.Height = Me.Height - 35
            Me.FlowLayoutPanel1.Refresh()
     
     
     
            'Me.Button1.Left = Me.Width / 2 - 46
            'Me.Button1.Top = Me.Height - 80
     
        End Sub
     
     
     
        'Private Sub Button2_Click(sender As Object, e As EventArgs)
        '    On Error Resume Next
        '    Process.Start(Me.Button2.AccessibleDescription)
        'End Sub
     
        Public Sub New()
     
            ' Cet appel est requis par le concepteur.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
     
        End Sub
     
     
     
     
        Private Sub Button1_Click(sender As Object, e As EventArgs)
     
     
            My.Settings.collection1.Clear()
            My.Settings.collection1.Add("a")
            Me.FlowLayoutPanel1.Controls.Clear()
     
        End Sub
     
        Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
     
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Owner.Left = MousePosition.X - mousex
                Me.Owner.Top = MousePosition.Y - mousey
                'Me.Location = New Point(MousePosition.X, MousePosition.Y)
     
     
            End If
     
        End Sub
     
        Dim mousex As Integer
        Dim mousey As Integer
        Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
            mousex = Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable mousex
            mousey = Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable 
        End Sub
     
        Private Sub FlowLayoutPanel1_MouseDown(sender As Object, e As MouseEventArgs) Handles FlowLayoutPanel1.MouseDown
            mousex = Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable mousex
            mousey = Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable 
        End Sub
     
        Private Sub FlowLayoutPanel1_MouseMove(sender As Object, e As MouseEventArgs) Handles FlowLayoutPanel1.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Left Then
                Me.Owner.Left = MousePosition.X - mousex
                Me.Owner.Top = MousePosition.Y - mousey
                'Me.Location = New Point(MousePosition.X, MousePosition.Y)
     
     
            End If
        End Sub
     
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
     
            Dim nom As String
            nom = InputBox("Veuillez indiquer le nom de la fenêtre", "Nom de la fenêtre")
     
            Form3.Label1.Text = nom
     
        End Sub
     
        Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
     
            If ColorDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
                Me.Owner.BackColor = ColorDialog1.Color
     
            End If
     
        End Sub
     
     
     
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
     
            Dim bb As New Form3
            bb.Show()
        End Sub
    End Class

    si vous lancez ce code, en cliquant sur le bouton 4, on peut dupliquer les deux forms et les propriétés de chaque form s'applique à la copie!

    A bientôt!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Variables entre deux fenêtres windows form
    Par miklmikl dans le forum C++
    Réponses: 8
    Dernier message: 27/05/2010, 12h09
  2. [XHTML 1.0] Confusion de deux forms imbriqués
    Par Lenezir dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 22/03/2009, 17h57
  3. Enregistrement avec deux windows form
    Par ApprentiDeveloppeur dans le forum Windows Forms
    Réponses: 2
    Dernier message: 01/09/2008, 13h46
  4. [C#] windows form et ComboBox
    Par telynor dans le forum Windows Forms
    Réponses: 9
    Dernier message: 12/11/2004, 18h17
  5. [VB.NET] windows form traits
    Par DG JohnJohn dans le forum Windows Forms
    Réponses: 3
    Dernier message: 08/06/2004, 15h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo