Vous êtes sur la page 1sur 2

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.

Text; using System.Windows.Forms; namespace Win_ordenar_STRING { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Width = 195; } public string[] Palabras; public int n,i; private void buttonOk_Click(object sender, EventArgs e) { n = int.Parse(textBox1.Text); Palabras = new string[n]; textBox1.Enabled = false; buttonOk.Enabled = false; textBox2.Focus(); } private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { if (Char.IsLetter(e.KeyChar)) { e.Handled = false; } else if (Char.IsControl(e.KeyChar)) { e.Handled = false; } else if (Char.IsSeparator(e.KeyChar)) { e.Handled = false; } else { e.Handled = true; } if (e.KeyChar == 13) { Palabras[i] = textBox2.Text; labelN.Text = "" + ((i + 1) + 1) + " :"; i++; if (i == n) { labelN.Text = ""; textBox2.Enabled = false; } listBox1.Items.Add(" "+i+".- "+textBox2.Text);//agregamos los nu

meros al listbox1 textBox2.Clear(); textBox2.Focus(); } } private void buttonOrdenar_Click(object sender, EventArgs e) { this.Width = 360; //Ordenar(Palabras); for (int k = 0; k < n; k++) { for (int i = 0; i < n - 1; i++) { if (Palabras[i].CompareTo(Palabras[i+1])>0 ) { string aux; aux = Palabras[i]; Palabras[i] = Palabras[i + 1]; Palabras[i + 1] = aux; } } } for (int i = 0,j=1; i < n; i++,j++) { listBox2.Items.Add(" " + j + ".- " + Palabras[i]); } buttonOrdenar.Enabled = false; } private void buttonNuevo_Click(object sender, EventArgs e) { textBox1.Clear(); textBox2.Clear(); textBox1.Enabled = true; textBox2.Enabled = true; buttonOk.Enabled = true; buttonOrdenar.Enabled = true; listBox1.Items.Clear(); listBox2.Items.Clear(); } private void btnSalir_Click(object sender, EventArgs e) { this.Close(); } } }