Bon, je me suis essayé au C# pour créer une application. C'est une partie de mon application qui a pour but de lister dans un combobox (liste deroulante) la liste des répertoire présent dans un dossier.
Dans mon exemple, je prend liste les répertoires présent dans "C:\Windows\".
Voici le code :
using System; using System.Drawing; using System.Windows.Forms; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Lister_répertoire { public partial class Form1 : Form { private Button valid = new Button(); private ComboBox combo = new ComboBox(); private Label label = new Label(); public Form1() { valid.Text = "Valider"; Size = new Size(200, 200); Text = ("Lister répertoire"); label.Location = new Point(5, 5); label.Size = new Size(200, 20); label.Text = "Veuillez Choisir votre répertoire : "; valid.Location = new Point(55, 130); combo.Location = new Point(10, 30); combo.Size = new Size(150, 20); DirectoryInfo MyRoot = new DirectoryInfo(@"C:\Windows\"); DirectoryInfo[] MyFiles = MyRoot.GetDirectories(); foreach (DirectoryInfo F in MyFiles) { combo.Items.Add(F.Name); } Controls.Add(label); Controls.Add(valid); Controls.Add(combo); valid.Click += new EventHandler(Draw_Click); } protected void Draw_Click(Object sender, EventArgs e) { MessageBox.Show("Valider"); } } }
A bientôt,
Romain