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 :

Problème de textbox! [Débutant]


Sujet :

Windows Forms

  1. #1
    Membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2012
    Messages
    102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2012
    Messages : 102
    Points : 41
    Points
    41
    Par défaut Problème de textbox!
    Bonjour ou bonsoir!^^
    Voilà depuis quelques jours, j'ai créer un logiciel qui génère des quêtes pour un script sur rpg maker vx ace.

    J'ai une classe qui se nomme: "Quest", j'utilise ce code, pour sauvegarder:
    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
                try
                {
                    using (BinaryWriter binaryWriter = new BinaryWriter((Stream)File.Open(this.folderBrowserDialog1.SelectedPath + "\\Data\\Quests.rvdata2", FileMode.Create)))
                    {
                        binaryWriter.Write(this.quests.Length);
                        for (int index1 = 0; index1 < this.quests.Length; ++index1)
                        {
                            binaryWriter.Write(this.quests[index1].Name);
                            binaryWriter.Write(this.quests[index1].Giver);
                            binaryWriter.Write(this.quests[index1].Location);
                            binaryWriter.Write(this.quests[index1].Description);
                            binaryWriter.Write(this.quests[index1].QuestNote);
                            binaryWriter.Write(this.quests[index1].Level);
                            binaryWriter.Write(this.quests[index1].IconIndex);
                            binaryWriter.Write(this.quests[index1].NumberObjectives);
                            for (int index2 = 0; index2 <= this.quests[index1].NumberObjectives; ++index2)
                                binaryWriter.Write(this.quests[index1].Objectives[index2]);
                            binaryWriter.Write(this.quests[index1].items.Count);
                            for (int index2 = 0; index2 < this.quests[index1].items.Count; ++index2)
                            {
                                binaryWriter.Write(this.quests[index1].items[index2].type);
                                binaryWriter.Write(this.quests[index1].items[index2].itemid);
                                binaryWriter.Write(this.quests[index1].items[index2].itemnumber);
                            }
                            binaryWriter.Write(this.quests[index1].Catégorie);
                            binaryWriter.Write(this.quests[index1].EvCommun);
                            binaryWriter.Write(this.quests[index1].Banniere);
                            binaryWriter.Write(this.quests[index1].Teinte);
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Aucun projet ouvert!", "Save impossible:");
                }
    Et la pour ouvrir: (Je voudrais savoir comment faire si l'utilisateur a cliquer sur ok dans le folderbrowserdialog, pour qui active le code, si il clique sur annuler sa fait rien)
    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
                try
                {
                    int num1 = (int)this.folderBrowserDialog1.ShowDialog();
                    if (File.Exists(this.folderBrowserDialog1.SelectedPath + "\\Data\\Quests.rvdata2")) 
                    {
                        using (BinaryReader binaryReader = new BinaryReader((Stream)File.Open(this.folderBrowserDialog1.SelectedPath + "\\Data\\Quests.rvdata2", FileMode.Open)))
                        { 
                            int length = binaryReader.ReadInt32();
                            this.quests = new Quest[length];
                            this.listBox1.Items.Clear();
                            for (int index1 = 0; index1 < length; ++index1) 
                            {   
                                this.quests[index1] = new Quest("");
                                this.quests[index1].Name = binaryReader.ReadString();
                                this.quests[index1].Giver = binaryReader.ReadString();
                                this.quests[index1].Location = binaryReader.ReadString();
                                this.quests[index1].Description = binaryReader.ReadString();
                                this.quests[index1].QuestNote = binaryReader.ReadString();
                                this.quests[index1].Level = binaryReader.ReadInt32();
                                this.quests[index1].IconIndex = binaryReader.ReadInt32();
                                this.quests[index1].NumberObjectives = binaryReader.ReadInt32();
                                this.listBox1.Items.Add((object)this.quests[index1].Name);
                                this.quests[index1].Objectives.Clear();
                                for (int index2 = 0; index2 <= this.quests[index1].NumberObjectives; ++index2)
                                    this.quests[index1].Objectives.Add(binaryReader.ReadString());
                                int num2 = binaryReader.ReadInt32();
                                for (int index2 = 0; index2 < num2; ++index2)
                                { 
                                    this.quests[index1].items.Add(new Item(0, 0, 0));
                                    this.quests[index1].items[index2].type = binaryReader.ReadInt32();  
                                    this.quests[index1].items[index2].itemid = binaryReader.ReadInt32();
                                    this.quests[index1].items[index2].itemnumber = binaryReader.ReadInt32();
                                }
                                this.quests[index1].Catégorie = binaryReader.ReadString();
                                this.quests[index1].EvCommun = binaryReader.ReadInt32();
                                this.quests[index1].Banniere = binaryReader.ReadString();
                                this.quests[index1].Teinte = binaryReader.ReadInt32();
                            }
                        }
                    }
                    if (File.Exists(this.folderBrowserDialog1.SelectedPath + "\\Data\\Items.rvdata2"))   
                        File.Copy(this.folderBrowserDialog1.SelectedPath + "\\Data\\Items.rvdata2", "Projet\\Data\\Items.rvdata2");
                    if (File.Exists(this.folderBrowserDialog1.SelectedPath + "\\Data\\Armors.rvdata2"))
                        File.Copy(this.folderBrowserDialog1.SelectedPath + "\\Data\\Armors.rvdata2", "Projet\\Data\\Armors.rvdata2");
                    if (File.Exists(this.folderBrowserDialog1.SelectedPath + "\\Data\\Weapons.rvdata2"))
                        File.Copy(this.folderBrowserDialog1.SelectedPath + "\\Data\\Weapons.rvdata2", "Projet\\Data\\Weapons.rvdata2");
                    this.LoadTimer1.Enabled = true;
                    this.ouvrirToolStripButton.Enabled = false;
                }
                catch (Exception)
                {
                    MessageBox.Show("Un projet est ouvert!", "Ouverture impossible:");
                }
    Quand on ouvre un projet, la listbox1 sélectionne le premier, puis le textbox reste a la valeur d'actuel, c'est ta dire rien, il affiche pas la phrase de l'utilisateur.
    Ou provient l'erreur?
    Merci d'avance de m'aider.

  2. #2
    Membre chevronné
    Avatar de PixelJuice
    Homme Profil pro
    Ingénieur .NET & Game Designer
    Inscrit en
    Janvier 2014
    Messages
    641
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Ingénieur .NET & Game Designer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 641
    Points : 2 157
    Points
    2 157
    Par défaut
    Pour ton problème de FolderBrowserDialog , on fait généralement comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                {
                    // Choses a faire si le dialogue a été validé
                }
    Cela permet d'afficher le dialog , puis de ne faire que les traitements si l'utilisateur a bien validé celui-ci.

    Quand on ouvre un projet, la listbox1 sélectionne le premier, puis le textbox reste a la valeur d'actuel, c'est ta dire rien, il affiche pas la phrase de l'utilisateur.
    Ou provient l'erreur?
    La je ne vois pas trop de quoi tu parles , c'est un peu flou.

  3. #3
    Membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2012
    Messages
    102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2012
    Messages : 102
    Points : 41
    Points
    41
    Par défaut
    Voilà, quand j'ouvre, le logiciel ouvre le document "Quest.rvdata2" et lit les ligne du document.
    Mais le seul probléme:
    L'objective: 0 de la quêtes n°0, ne met pas la phrase qui est dans le document "Quest.rvdata2"!^^'

    Voilà le logiciel:
    http://sourceforge.net/projects/logi...r.zip/download

    En haut du sujet j'ai mis le code ou il l'ouvre le document "Quest.rvdata2" et l'enregistre.

  4. #4
    Membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2012
    Messages
    102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2012
    Messages : 102
    Points : 41
    Points
    41
    Par défaut
    Je fait un petit UP!^^
    Car c'est vraiment embêtant ce bug!^^

  5. #5
    Membre chevronné
    Avatar de PixelJuice
    Homme Profil pro
    Ingénieur .NET & Game Designer
    Inscrit en
    Janvier 2014
    Messages
    641
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Ingénieur .NET & Game Designer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 641
    Points : 2 157
    Points
    2 157
    Par défaut
    Et c'est quoi le type de control qui représente les objectifs ? Tu n'as pas donné de nom explicite a tes controls donc on sait pas qui fait quoi , si tu pouvais nous éclairer d'avantage.

  6. #6
    Membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2012
    Messages
    102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2012
    Messages : 102
    Points : 41
    Points
    41
    Par défaut
    Désoler pour oublier des choses!^^'

    Ceci est une class, qui se nomme "Quest".
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace VXAceQuest
    {
        public class Quest
        {
            public string Name { get; set; }
     
            public int Level { get; set; }
     
            public string Giver { get; set; }
     
            public string Location { get; set; }
     
            public int IconIndex { get; set; }
     
            public string Description { get; set; }
     
            public List<string> Objectives { get; set; }
     
            public int NumberObjectives { get; set; }
     
            public string QuestNote { get; set; }
     
            public List<Item> items { get; set; }
     
            public string Banniere { get; set; }
     
            public int EvCommun { get; set; }
     
            public int Teinte { get; set; }
     
            public string Catégorie { get; set; }
     
            public Quest(string name)
            {
                this.Name = name;
                this.Level = 0;
                this.Giver = "";
                this.Location = "";
                this.IconIndex = 0;
                this.Description = "";
                this.Objectives = new List<string>();
                this.Objectives.Add("");
                this.NumberObjectives = 0;
                this.QuestNote = "";
                this.items = new List<Item>();
                this.Banniere = "";
                this.EvCommun = 0;
                this.Teinte = 0;
                this.Catégorie = "";
            }
     
            public void addObjective()
            {
                this.Objectives.Add("");
            }
        }
    }
    Ici c'est le code ou j'ouvre un projet rpg maker VXAce, que si, dans le dossier "Data\Quest.rvdata2" existe, si oui il le lit.
    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
                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        //int num1 = (int)this.folderBrowserDialog1.ShowDialog();
                        if (File.Exists(this.folderBrowserDialog1.SelectedPath + "\\Data\\Quests.rvdata2"))
                        {
                            using (BinaryReader binaryReader = new BinaryReader((Stream)File.Open(this.folderBrowserDialog1.SelectedPath + "\\Data\\Quests.rvdata2", FileMode.Open)))
                            {
                                int length = binaryReader.ReadInt32();
                                this.quests = new Quest[length];
                                this.listBox1.Items.Clear();
                                for (int index1 = 0; index1 < length; ++index1)
                                {
                                    this.quests[index1] = new Quest("");
                                    this.quests[index1].Name = binaryReader.ReadString();
                                    this.quests[index1].Giver = binaryReader.ReadString();
                                    this.quests[index1].Location = binaryReader.ReadString();
                                    this.quests[index1].Description = binaryReader.ReadString();
                                    this.quests[index1].QuestNote = binaryReader.ReadString();
                                    this.quests[index1].Level = binaryReader.ReadInt32();
                                    this.quests[index1].IconIndex = binaryReader.ReadInt32();
                                    this.quests[index1].NumberObjectives = binaryReader.ReadInt32();
                                    this.listBox1.Items.Add((object)this.quests[index1].Name);
                                    this.quests[index1].Objectives.Clear();
                                    for (int index2 = 0; index2 <= this.quests[index1].NumberObjectives; ++index2)
                                        this.quests[index1].Objectives.Add(binaryReader.ReadString());
                                    int num2 = binaryReader.ReadInt32();
                                    for (int index2 = 0; index2 < num2; ++index2)
                                    {
                                        this.quests[index1].items.Add(new Item(0, 0, 0));
                                        this.quests[index1].items[index2].type = binaryReader.ReadInt32();
                                        this.quests[index1].items[index2].itemid = binaryReader.ReadInt32();
                                        this.quests[index1].items[index2].itemnumber = binaryReader.ReadInt32();
                                    }
                                    this.quests[index1].Catégorie = binaryReader.ReadString();
                                    this.quests[index1].EvCommun = binaryReader.ReadInt32();
                                    this.quests[index1].Banniere = binaryReader.ReadString();
                                    this.quests[index1].Teinte = binaryReader.ReadInt32();
                                }
                            }
                        }
                        if (File.Exists(this.folderBrowserDialog1.SelectedPath + "\\Data\\Items.rvdata2"))
                            File.Copy(this.folderBrowserDialog1.SelectedPath + "\\Data\\Items.rvdata2", "Projet\\Data\\Items.rvdata2");
                        if (File.Exists(this.folderBrowserDialog1.SelectedPath + "\\Data\\Armors.rvdata2"))
                            File.Copy(this.folderBrowserDialog1.SelectedPath + "\\Data\\Armors.rvdata2", "Projet\\Data\\Armors.rvdata2");
                        if (File.Exists(this.folderBrowserDialog1.SelectedPath + "\\Data\\Weapons.rvdata2"))
                            File.Copy(this.folderBrowserDialog1.SelectedPath + "\\Data\\Weapons.rvdata2", "Projet\\Data\\Weapons.rvdata2");
                        this.LoadTimer1.Enabled = true;
                        this.ouvrirToolStripButton.Enabled = false;
                        this.enregistrerToolStripButton.Enabled = true;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Un projet est ouvert!", "Ouverture impossible:");
                    }
                }
    Et là c'est ou il enregistre a l'endroit qui a choisie dans le folderBrowserDialog1.
    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
                try
                {
                    using (BinaryWriter binaryWriter = new BinaryWriter((Stream)File.Open(this.folderBrowserDialog1.SelectedPath + "\\Data\\Quests.rvdata2", FileMode.Create)))
                    {
                        binaryWriter.Write(this.quests.Length);
                        for (int index1 = 0; index1 < this.quests.Length; ++index1)
                        {
                            binaryWriter.Write(this.quests[index1].Name);
                            binaryWriter.Write(this.quests[index1].Giver);
                            binaryWriter.Write(this.quests[index1].Location);
                            binaryWriter.Write(this.quests[index1].Description);
                            binaryWriter.Write(this.quests[index1].QuestNote);
                            binaryWriter.Write(this.quests[index1].Level);
                            binaryWriter.Write(this.quests[index1].IconIndex);
                            binaryWriter.Write(this.quests[index1].NumberObjectives);
                            for (int index2 = 0; index2 <= this.quests[index1].NumberObjectives; ++index2)
                                binaryWriter.Write(this.quests[index1].Objectives[index2]);
                            binaryWriter.Write(this.quests[index1].items.Count);
                            for (int index2 = 0; index2 < this.quests[index1].items.Count; ++index2)
                            {
                                binaryWriter.Write(this.quests[index1].items[index2].type);
                                binaryWriter.Write(this.quests[index1].items[index2].itemid);
                                binaryWriter.Write(this.quests[index1].items[index2].itemnumber);
                            }
                            binaryWriter.Write(this.quests[index1].Catégorie);
                            binaryWriter.Write(this.quests[index1].EvCommun);
                            binaryWriter.Write(this.quests[index1].Banniere);
                            binaryWriter.Write(this.quests[index1].Teinte);
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Aucun projet ouvert!", "Save impossible:");
                }
    Voilà, puis dans la textBox6 qui enregistre les données:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
            private void textBox6_TextChanged(object sender, EventArgs e)
            {
                this.quests[this.listBox1.SelectedIndex].Objectives[this.tabControl1.SelectedIndex] = this.textBox6.Text;
            }
    tabControl1
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
            private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (this.deleted || this.tabControl1.TabCount != this.quests[this.listBox1.SelectedIndex].NumberObjectives + 1)
                    return;
                this.textBox6.Text = this.quests[this.listBox1.SelectedIndex].Objectives[this.tabControl1.SelectedIndex];
                this.lastSelectedpage = this.tabControl1.SelectedIndex;
            }
    Le bouton qui ajoute un objective:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
            private void button2_Click(object sender, EventArgs e)
            {
                ++this.quests[this.listBox1.SelectedIndex].NumberObjectives;
                this.tabControl1.TabPages.Add("Objectives: " + this.quests[this.listBox1.SelectedIndex].NumberObjectives.ToString());
                this.quests[this.listBox1.SelectedIndex].addObjective();
            }
    Le bouton qui supprime un objective:
    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
            private void button3_Click(object sender, EventArgs e)
            {
                if (tabControl1.TabPages.Count.Equals(1))
                {
                    this.textBox6.Text = "";
                }
                else
                {
                    this.deleted = true;
                    this.quests[this.listBox1.SelectedIndex].Objectives.RemoveAt(this.tabControl1.SelectedIndex);
                    --this.quests[this.listBox1.SelectedIndex].NumberObjectives;
                    this.lastSelectedpage = 0;
                    this.tabControl1.TabPages.Clear();
                    for (int index = 0; index <= this.quests[this.listBox1.SelectedIndex].NumberObjectives; ++index)
                        this.tabControl1.TabPages.Add("Objectives: " + index.ToString());
                    this.tabControl1.SelectedIndex = 0;
                    this.textBox6.Text = this.quests[this.listBox1.SelectedIndex].Objectives[0];
                    this.timer1.Enabled = true;
                }
            }
    Voilà, j'éspére que tu a tout pour m'aider!^^
    Ah! J'oublier j'ai ce code dans le textBox1:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                this.quests[this.listBox1.SelectedIndex].Name = this.textBox1.Text;
                this.listBox1.Items[listBox1.SelectedIndex] = this.textBox1.Text;
                this.textBox1.Focus();
                this.textBox1.SelectionStart = this.textBox1.Text.Length;
            }
    Il renomme bien la sélection dans la listBox1, mais hélas on peut plus écrire, a chaque fois je suis obliger de cliquer, mais depuis ce code, je peut plus retourner en arrière!^^'

  7. #7
    Membre du Club
    Homme Profil pro
    Inscrit en
    Septembre 2012
    Messages
    102
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2012
    Messages : 102
    Points : 41
    Points
    41
    Par défaut
    Je up juste pour la textbox1!

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

Discussions similaires

  1. Problème de TextBox numérique
    Par Lutine dans le forum VB.NET
    Réponses: 25
    Dernier message: 23/07/2007, 13h28
  2. Problème onChange TEXTBOX
    Par actarus108 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 25/05/2007, 21h15
  3. Problème avec Textbox
    Par Appwal dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 11/04/2007, 16h52
  4. Problème avec TextBox
    Par @yoyo dans le forum Windows Forms
    Réponses: 6
    Dernier message: 15/02/2007, 16h47
  5. [VB6] Problème de textbox multiligne qui génére une erreur
    Par bb62 dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 20/02/2006, 16h21

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