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

VB.NET Discussion :

Problème avec onglets multiples


Sujet :

VB.NET

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 42
    Par défaut Problème avec onglets multiples
    Bonjour, dans le cadre du devellopement d'un logiciel, j'ai besoin d'onglets que l'utilisateur puisse ouvrir et fermer a volonté, un peu comme dans notepad++ ou firefox. C'est pour un editeur de texte. Dans chacun de ces onglets il y a une richtextbox ainsi qu'un bouton. J'ai donc plusieurs problèmes :

    - Comment, quand j'ouvre un fichier texte, l'ouvrir dans la bonne richtextbox, celle qui correspond à l'onglet selectionné ?

    - Comment mettre du code à executer pour tous les nouveaux bouton créés (à chaque fois le meme code, pour tous les boutons) ?

    Un petit screen pour que vous compreniez mieux :


    ainsi que le code :
    Code : 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
    Imports System.IO
    Imports mRibbon
    Imports Vista_Api
     
    Public Class Twinotes
        Dim nbonglet As Integer = 0
     
        Private Sub bandeau_Options_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bandeau_Options.Click
            Me.Visible = False
            Accueil.Text = "wTwin"
        End Sub
     
        Private Sub Themebleu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Themebleu.Click
            RibbonControl.ColorScheme = mRibbon.ColorScheme.Blue
            bandeau_Options.Invalidate()
            bandeau_Texte.Invalidate()
            Dim SW As StreamWriter
            SW = File.CreateText("C:\Program Files\wTwin\config.ini")
            SW.WriteLine("0")
            SW.Close()
        End Sub
     
        Private Sub Themegris_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Themegris.Click
            RibbonControl.ColorScheme = mRibbon.ColorScheme.Gray
            bandeau_Options.Invalidate()
            bandeau_Texte.Invalidate()
            Dim SW As StreamWriter
            SW = File.CreateText("C:\Program Files\wTwin\config.ini")
            SW.WriteLine("1")
            SW.Close()
        End Sub
     
        Private Sub Themechoix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Themechoix.Click
            If ColorDialog1.ShowDialog() = DialogResult.OK Then
                RibbonControl.ColorScheme = mRibbon.ColorScheme.Custom
                RibbonControl.Color = ColorDialog1.Color
                bandeau_Options.Invalidate()
                bandeau_Texte.Invalidate()
                Dim SW As StreamWriter
                SW = File.CreateText("C:\Program Files\wTwin\config.ini")
                SW.WriteLine("2")
                SW.Close()
            End If
        End Sub
     
        Private Sub Nouveau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nouveau.Click
            Dim Tabp As New TabPage
            With Tabp
                .Text = "Nouveau" & " " & nbonglet
                .Name = "onglet" & nbonglet
            End With
            bandeau_Texte.Controls.Add(Tabp)
            Dim rtb As New RichTextBox
            With rtb
                .Size = New System.Drawing.Size(786, 412)
                .Location = New System.Drawing.Point(0, 0)
                .Name = "Textenote" & nbonglet
                .ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical
            End With
            Tabp.Controls.Add(rtb)
            Dim EnvoiTwin As New CommandLink
            With EnvoiTwin
                .Location = New System.Drawing.Point(558, 347)
                .Name = "EnvoiTwin" & nbonglet
                .Size = New System.Drawing.Size(205, 60)
                .Text = "Envoyer vers le Twin"
            End With
            rtb.Controls.Add(EnvoiTwin)
        End Sub
     
        Private Sub EnvoiTwin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnvoiTwin.Click
            Dim texte, titre As String
            texte = Textenote.Text
            titre = Onglet1.Text
            For Each di As DriveInfo In DriveInfo.GetDrives()
                If di.IsReady Then
                    If di.VolumeLabel = "MYPHONE" Then
                        If Not texte = Nothing Then
                            Dim lettre As String
                            lettre = di.Name
                            Dim SW As StreamWriter
                            SW = File.CreateText(lettre & titre & ".txt")
                            SW.WriteLine(texte$)
                            SW.Close()
                        Else : MsgBox("Vous n'avez pas renseigné tous les champs disponibles", MsgBoxStyle.Exclamation)
                        End If
                    End If
                End If
            Next
        End Sub
     
        Private Sub tabremoved_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles bandeau_Texte.ControlRemoved
            Dim i As Integer
            i = bandeau_Texte.TabCount - 2
            If i = 1 Then
                Nbonglets.Text = i & " " & "onglet ouvert"
            ElseIf i > 1 Then
                Nbonglets.Text = i & " " & "onglets ouverts"
            End If
            bandeau_Texte.SelectTab(i)
        End Sub
     
        Private Sub tabadded_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles bandeau_Texte.ControlAdded
            Dim i As Integer
            i = bandeau_Texte.TabCount - 1
            If i = 1 Then
                Nbonglets.Text = i & " " & "onglet ouvert"
            ElseIf i > 1 Then
                Nbonglets.Text = i & " " & "onglets ouverts"
            End If
            bandeau_Texte.SelectTab(i)
            nbonglet += 1
        End Sub
     
        Private Sub Ouvrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ouvrir.Click
            If Not Textenote.Text = "" Then
                Form1.Label1.Text = bandeau_Texte.SelectedTab.Text & " " & "a des modifications non enregistrées. Que voulez vous faire ?"
                Form1.ShowDialog()
            ElseIf Textenote.Text = "" Then
                OpenFileDialog1.Filter = "Texte (*.txt)|*.txt"
                If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    Dim CheminFichier As String
                    CheminFichier = OpenFileDialog1.FileName
                    Try
                        Dim Fichier As New System.IO.StreamReader(CheminFichier)
                        Textenote.Text = Fichier.ReadToEnd
                        Fichier.Close()
                    Catch ex As System.Exception
                        MsgBox("Impossible d'ouvrir le fichier, il est peut être en cours d'utilisation", MsgBoxStyle.Critical)
                    Finally
                    End Try
                    bandeau_Texte.SelectedTab.Text = Path.GetFileNameWithoutExtension(CheminFichier)
                End If
            End If
        End Sub
     
        Private Sub Suppronglet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Suppronglet.Click
            If Not Textenote.Text = "" Then
                Form2.Label1.Text = bandeau_Texte.SelectedTab.Text & " " & "a des modifications non enregistrées. Que voulez vous faire ?"
                Form2.ShowDialog()
            ElseIf Textenote.Text = "" Then
                Dim i As Integer
                i = bandeau_Texte.TabCount
                If bandeau_Texte.TabCount > 2 Then
                    bandeau_Texte.TabPages.RemoveAt(bandeau_Texte.SelectedIndex)
                End If
            End If
        End Sub
     
        Private Sub Annuler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Annuler.Click
            Textenote.Undo()
        End Sub
     
        Private Sub Suivant_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Suivant.Click
            Textenote.Redo()
        End Sub
     
        Private Sub RibbonItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonItem1.Click
            Textenote.Copy()
        End Sub
     
        Private Sub RibbonItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonItem2.Click
            Textenote.Paste()
        End Sub
    End Class
    Merci de votre aide.

  2. #2
    Membre éclairé

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    291
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 291
    Par défaut
    Salut,

    - Comment, quand j'ouvre un fichier texte, l'ouvrir dans la bonne richtextbox, celle qui correspond à l'onglet selectionné ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    MessageBox.Show("Index de l'onglet sélectionné (0 est le premier): " & Me.tabcVehicule.SelectedIndex & " -- Nom de l'onglet: " & Me.tabcVehicule.SelectedTab.Name)
    - Comment mettre du code à executer pour tous les nouveaux bouton créés (à chaque fois le meme code, pour tous les boutons) ?
    Regarde du côté de Handles

    Bonne continuation

    Gwendal

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2007
    Messages : 9
    Par défaut
    Citation Envoyé par moimael
    Bonjour, dans le cadre du devellopement d'un logiciel, j'ai besoin d'onglets que l'utilisateur puisse ouvrir et fermer a volonté, un peu comme dans notepad++ ou firefox. C'est pour un editeur de texte. Dans chacun de ces onglets il y a une richtextbox ainsi qu'un bouton. J'ai donc plusieurs problèmes :

    - Comment, quand j'ouvre un fichier texte, l'ouvrir dans la bonne richtextbox, celle qui correspond à l'onglet selectionné ?

    - Comment mettre du code à executer pour tous les nouveaux bouton créés (à chaque fois le meme code, pour tous les boutons) ?

    Un petit screen pour que vous compreniez mieux :


    ainsi que le code :
    Code : 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
    Private Sub Nouveau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nouveau.Click
            Dim i As Integer
            i = bandeau_Texte.SelectedIndex - 1
            Dim Tabp As New TabPage
            Tabp.Text = "Nouveau" & " " & bandeau_Texte.TabCount
            bandeau_Texte.Controls.Add(Tabp)
            Dim rtb As New RichTextBox
            With rtb
                .Size = New System.Drawing.Size(786, 412)
                .Location = New System.Drawing.Point(-2, 0)
                .Name = "Textenote" & i
                .ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical
            End With
            Tabp.Controls.Add(rtb)
            Dim EnvoiTwin As New CommandLink
            With EnvoiTwin
                .Location = New System.Drawing.Point(558, 347)
                .Name = "EnvoiTwin"
                .Size = New System.Drawing.Size(205, 60)
                .Text = "Envoyer vers le Twin"
            End With
            rtb.Controls.Add(EnvoiTwin)
            bandeau_Texte.SelectTab(i)
        End Sub
     
        Private Sub EnvoiTwin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnvoiTwin.Click
            Dim texte, titre As String
            texte = Textenote.Text
            titre = TabPage4.Text
            For Each di As DriveInfo In DriveInfo.GetDrives()
                If di.IsReady Then
                    If di.VolumeLabel = "MYPHONE" Then
                        If Not texte = Nothing Then
                            Dim lettre As String
                            lettre = di.Name
                            Dim SW As StreamWriter
                            SW = File.CreateText(lettre & titre & ".txt")
                            SW.WriteLine(texte$)
                            SW.Close()
                        Else : MsgBox("Vous n'avez pas renseigné tous les champs disponibles", MsgBoxStyle.Exclamation)
                        End If
                    End If
                End If
            Next
        End Sub
     
        Private Sub tabremoved_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles bandeau_Texte.ControlRemoved
            Dim i As Integer
            i = bandeau_Texte.TabCount - 2
            If i = 1 Then
                TabPage3.Text = i & " " & "onglet ouvert"
            ElseIf i > 1 Then
                TabPage3.Text = i & " " & "onglets ouverts"
            End If
            bandeau_Texte.SelectTab(TabPage4)
            bandeau_Texte.Refresh()
        End Sub
     
        Private Sub tabadded_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles bandeau_Texte.ControlAdded
            Dim i As Integer
            i = bandeau_Texte.TabCount - 1
            If i = 1 Then
                TabPage3.Text = i & " " & "onglet ouvert"
            ElseIf i > 1 Then
                TabPage3.Text = i & " " & "onglets ouverts"
            End If
        End Sub
     
        Private Sub Ouvrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ouvrir.Click
            OpenFileDialog1.Filter = "Texte (*.txt)|*.txt"
            If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                If Not Textenote.Text = "" Then
                    If MsgBox("Etes vous sur de vouloir effacer votre travail en cours ?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                        Dim CheminFichier As String
                        CheminFichier = OpenFileDialog1.FileName
                        Try
                            Dim Fichier As New System.IO.StreamReader(CheminFichier)
                            Textenote.Text = Fichier.ReadToEnd
                            Fichier.Close()
                        Catch ex As System.InvalidOperationException
                            MsgBox("Impossible d'ouvrir le fichier, il est peut être en cours d'utilisation", MsgBoxStyle.Critical)
                        Finally
                        End Try
                        bandeau_Texte.SelectedTab.Text = Path.GetFileNameWithoutExtension(CheminFichier)
                    End If
                End If
            End If
            If Textenote.Text = "" Then
                Dim CheminFichier As String
                CheminFichier = OpenFileDialog1.FileName
                Try
                    Dim Fichier As New System.IO.StreamReader(CheminFichier)
                    Textenote.Text = Fichier.ReadToEnd
                    Fichier.Close()
                Catch ex As System.InvalidOperationException
                    MsgBox("Impossible d'ouvrir le fichier, il est peut être en cours d'utilisation", MsgBoxStyle.Critical)
                Finally
                End Try
                bandeau_Texte.SelectedTab.Text = Path.GetFileNameWithoutExtension(CheminFichier)
            End If
        End Sub
     
        Private Sub RibbonButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonButton1.Click
            Dim i As Integer
            i = bandeau_Texte.TabCount
            Dim index As Integer
            index = bandeau_Texte.TabPages.IndexOf(TabPage4)
            If bandeau_Texte.SelectedIndex > index Then
                bandeau_Texte.TabPages.RemoveAt(bandeau_Texte.SelectedIndex)
            End If
        End Sub
    Merci de votre aide.
    Rien avoir avec ta question mais comment as tu créer cet effet Office 2007 like pour ton menu ?

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    42
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 42
    Par défaut
    Merci pour ta réponse Gdal je vais essayer de voir comment faire avec tes indication

    Eggiz, je me sers d'une dll nommé mentas Ribbon trouvable ici et utilisable très simplement :

Discussions similaires

  1. [MySQL] Problème avec connection multiple mysql et fonction php
    Par mitchb dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 07/08/2009, 11h41
  2. Problème avec jointures multiples.
    Par Veritas5 dans le forum Développement
    Réponses: 3
    Dernier message: 05/06/2009, 15h42
  3. Problème avec la multiplication des images
    Par twix24 dans le forum Images
    Réponses: 4
    Dernier message: 12/12/2007, 09h07
  4. [CSS] Problème avec onglets
    Par jehlg dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 28/03/2006, 11h15
  5. Réponses: 22
    Dernier message: 05/07/2005, 00h04

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