string Texte = textBox7.Text; string[] MesNombres = Texte.Split(Convert.Tochar("*"));
using System; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class frmTestSplit : Form { public frmTestSplit() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string[] MesNombres = textBox7.Text.Split(Convert.ToChar("*")); listBox1.DataSource = MesNombres; } #region Form1 Designer /// <summary> /// Variable nécessaire au concepteur. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Nettoyage des ressources utilisées. /// </summary> /// true si les ressources managées doivent être supprimées; sinon, false. protected override void Dispose(bool disposing) { if (disposing && (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.textBox7 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.listBox1 = new System.Windows.Forms.ListBox(); this.SuspendLayout(); // // textBox7 // this.textBox7.Location = new System.Drawing.Point(90, 12); this.textBox7.Name = "textBox7"; this.textBox7.Size = new System.Drawing.Size(100, 20); this.textBox7.TabIndex = 0; this.textBox7.Text = "1*23*456*7890"; // // button1 // this.button1.Location = new System.Drawing.Point(90, 49); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(100, 30); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // listBox1 // this.listBox1.FormattingEnabled = true; this.listBox1.Location = new System.Drawing.Point(79, 97); this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(120, 95); this.listBox1.TabIndex = 2; // // frmTestSplit // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.listBox1); this.Controls.Add(this.button1); this.Controls.Add(this.textBox7); this.Name = "frmTestSplit"; this.Text = "Form1"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox textBox7; private System.Windows.Forms.Button button1; private System.Windows.Forms.ListBox listBox1; #endregion } }
private void button1_Click(object sender, EventArgs e), dans laquelle un Split décompose le message et l'affiche dans la liste.
#region Form1 Designerse trouve habituellement dans le fichier Form1.Designer.cs, c'est Visual studio qui écrit ce code tout seul quand tu places des contrôles sur la Form.
private void button1_Click(object sender, EventArgs e)est abonnée à l'événement Clik de Button1 etc...
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question