Lexico
...el poder de lo simple...
Mayo.5.2010

Como utilizar controles ya existentes en .NET


La forma general es crear una aplicación dirigida por eventos y representada por una interfaz gráfica o ventana. Para ello se utiliza la clase Form ya existente en la plataforma:

1. Se programa una clase (
Lista en el ejemplo siguiente) y se heredan (derivada_de)  todas las características ya programadas en la clase Form.
2. Se crean los objetos de la clase de control ya existe en la plataforma (
Button y ListBox en el siguiente ejemplo).
3. Se agregan los controles (a la clase heredada .
AgregarControl en el siguiente ejemplo).
4. Se programan e inscriben los algoritmos controladores (
Listo en el siguiente ejemplo) para los eventos de los controles que se quieran escuchar, detectar, manejar o controlar (Manejador en el siguiente ejemplo).



/* Ejemplo de uso de controles ya programados en la plataforma .NET
versión C# tomada de la documentación en Microsoft:
http://msdn.microsoft.com/es-es/library/system.windows.forms.listbox(v=VS.80).aspx

private void button1_Click(object sender, System.EventArgs e)
{
   // Create an instance of the ListBox.
   ListBox listBox1 = new ListBox();
   // Set the size and location of the ListBox.
   listBox1.Size = new System.Drawing.Size(200, 100);
   listBox1.Location = new System.Drawing.Point(10,10);
   // Add the ListBox to the form.
   this.Controls.Add(listBox1);
   // Set the ListBox to display items in multiple columns.
   listBox1.MultiColumn = true;
   // Set the selection mode to multiple and extended.
   listBox1.SelectionMode = SelectionMode.MultiExtended;
 
   // Shutdown the painting of the ListBox as items are added.
   listBox1.BeginUpdate();
   // Loop through and add 50 items to the ListBox.
   for (int x = 1; x <= 50; x++)
   {
      listBox1.Items.Add("Item " + x.ToString());
   }
   // Allow the ListBox to repaint and display the new items.
   listBox1.EndUpdate();
     
   // Select three items from the ListBox.
   listBox1.SetSelected(1, true);
   listBox1.SetSelected(3, true);
   listBox1.SetSelected(5, true);

   // Display the second selected item in the ListBox to the console.
   System.Diagnostics.Debug.WriteLine(listBox1.SelectedItems[1].ToString());
   // Display the index of the first selected item in the ListBox.
   System.Diagnostics.Debug.WriteLine(listBox1.SelectedIndices[0].ToString());            
}
Versión completa en Lexico 3.0:*/

clase Lista derivada_de Form
publicos
el objeto b es un Button
mensajes
Lista
{
Lista.AgregarControl(b)
Lista.Manejador(b.ClickListo)
}

Listo(deme NC, deme paq es un EventArgs)
{
copie "Muestre Lista" en b.Text
copie Color.Yellow en b.BackColor

el objeto ListBox1 es un ListBox
el objeto Size es un Size(200, 100)
el objeto Sitio es un Point(10,30)
copie Size en ListBox1.Size
copie Sitio en ListBox1.location
Lista.AgregarControl(ListBox1)
copie verdadero en listBox1.MultiColumn
copie SelectionMode.MultiExtended en listBox1.SelectionMode
listBox1.BeginUpdate

el objeto x es una cantidad
variando x desde 1 hasta 50 haga:
    listBox1.Items.Add("Item " + x.ToString)

listBox1.EndUpdate

   listBox1.SetSelected(1, verdadero)
   listBox1.SetSelected(3, verdadero)
   listBox1.SetSelected(5, verdadero)

muestre listBox1.SelectedItems[1].ToString
muestre listBox1.SelectedItems[0].ToString
}





Aplicaciones dirigidas por eventos