Voilà le code de mon application: désolé si c'est un peu long.
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.IO; using System.Xml;
namespace fenetre_nom_projet { /// <summary> /// Description résumée de Form2. /// </summary> public class forme2 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.TextBox nom; private System.Windows.Forms.TextBox emplacement; private System.Windows.Forms.ErrorProvider errorProvider1; private string nom_projet; private string nom_chemin; private string nom_fichier_xml; private DirectoryInfo mon_rep;
/// <summary> /// Variable nécessaire au concepteur. /// </summary> private System.ComponentModel.Container components = null;
public forme2() { // // Requis pour la prise en charge du Concepteur Windows Forms // InitializeComponent();
// // TODO : ajoutez le code du constructeur après l'appel à InitializeComponent // }
/// <summary> /// Nettoyage des ressources utilisées. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); }
#region Code généré par le Concepteur Windows Form /// <summary> /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas /// le contenu de cette méthode avec l'éditeur de code. /// </summary> private void InitializeComponent() { this.nom = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.emplacement = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.errorProvider1 = new System.Windows.Forms.ErrorProvider(); this.panel1.SuspendLayout(); this.SuspendLayout(); // // nom // this.nom.Location = new System.Drawing.Point(80, 16); this.nom.Name = "nom"; this.nom.Size = new System.Drawing.Size(192, 20); this.nom.TabIndex = 0; this.nom.Text = ""; this.nom.Validating += new System.ComponentModel.CancelEventHandler(this.nom_Validating); // // label1 // this.label1.Location = new System.Drawing.Point(8, 24); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(48, 16); this.label1.TabIndex = 1; this.label1.Text = "nom"; // // panel1 // this.panel1.Controls.Add(this.button2); this.panel1.Controls.Add(this.button1); this.panel1.Controls.Add(this.emplacement); this.panel1.Controls.Add(this.label2); this.panel1.Controls.Add(this.label1); this.panel1.Controls.Add(this.nom); this.panel1.Location = new System.Drawing.Point(16, 32); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(280, 208); this.panel1.TabIndex = 2; // // button2 // this.button2.Location = new System.Drawing.Point(96, 96); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(72, 24); this.button2.TabIndex = 5; this.button2.Text = "ok"; this.button2.Click += new System.EventHandler(this.button2_Click); // // button1 // this.button1.Location = new System.Drawing.Point(200, 48); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(72, 24); this.button1.TabIndex = 4; this.button1.Text = "parcourir"; this.button1.Click += new System.EventHandler(this.button1_Click); // // emplacement // this.emplacement.Location = new System.Drawing.Point(80, 48); this.emplacement.Name = "emplacement"; this.emplacement.Size = new System.Drawing.Size(112, 20); this.emplacement.TabIndex = 3; this.emplacement.Text = ""; // // label2 // this.label2.Location = new System.Drawing.Point(0, 48); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(80, 32); this.label2.TabIndex = 2; this.label2.Text = "emplacement:"; // // errorProvider1 // this.errorProvider1.ContainerControl = this; // // forme2 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(296, 266); this.Controls.Add(this.panel1); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "forme2"; this.Text = "Nouveau projet"; this.panel1.ResumeLayout(false); this.ResumeLayout(false);
} #endregion static void Main() { Application.Run(new forme2()); }
private void button1_Click(object sender, System.EventArgs e) { FolderBrowserDialog Folder1 = new FolderBrowserDialog(); if ( Folder1.ShowDialog() == DialogResult.OK ) { //affichage dans la textBox emplacement.Text = Folder1.SelectedPath; //sauvegarde des donnéees dans les attributs de la fenêtre nom_chemin = Folder1.SelectedPath; } } public string get_chemin() { return nom_chemin; }
public string get_nom_projet() { return nom_projet; }
public string get_fichier_xml() { return nom_fichier_xml; }
public void button2_Click(object sender, System.EventArgs e) { if(nom.Text != "") { nom_projet = nom.Text; //creation du repertoire Oasis mon_rep = new DirectoryInfo(String.Concat(nom_chemin, @"\", nom_projet)); mon_rep.Create(); // creation du fichier xml nom_fichier_xml = String.Concat(nom_chemin, @"/", nom_projet, @"/annotations.xml"); XmlTextWriter tr = new XmlTextWriter(nom_fichier_xml, null); tr.Formatting = Formatting.Indented; tr.Flush(); tr.Close();
this.DialogResult = DialogResult.OK; } }
protected void nom_Validating (object sender, System.ComponentModel.CancelEventArgs e) { try { int x = Int32.Parse(nom.Text); errorProvider1.SetError(this.nom, ""); } catch (Exception f) { errorProvider1.SetError(this.nom, "Not an integer value."); } } } } Ced
|