Cómo: Habilitar la tabulación entre las formas (Visual Studio)

Actualización: Julio de 2008

Los controles de líneas y formas no tienen propiedades TabIndex sino TabStop, pero todavía puede habilitar la tabulación entre ellos. En el ejemplo siguiente, presionando las teclas CTRL y TAB, se tabulará entre las formas; presionando sólo la tecla TAB, se tabulará entre los botones.

Nota:

Es posible que su equipo muestre nombres o ubicaciones diferentes para algunos de los elementos de la interfaz de usuario de Visual Studio en las siguientes instrucciones. La edición de Visual Studio que tenga y la configuración que esté usando determinan estos elementos. Para obtener más información, vea Valores de configuración de Visual Studio.

Para habilitar la tabulación entre las formas

  1. Arrastre tres controles RectangleShape y dos controles Button desde el Cuadro de herramientas a un formulario.

  2. En el Editor de código, agregue una instrucción Imports o using al comienzo del módulo:

    Imports Microsoft.VisualBasic.PowerPacks
    
    using Microsoft.VisualBasic.PowerPacks;
    
  3. Agregue el código siguiente a un procedimiento de evento:

    Private Sub Shapes_PreviewKeyDown(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles _
     RectangleShape1.PreviewKeyDown, RectangleShape2.PreviewKeyDown, _
     RectangleShape3.PreviewKeyDown
        Dim sh As Shape
        ' Check for the Control and Tab keys.
        If e.KeyCode = Keys.Tab And e.Modifiers = Keys.Control Then
            ' Find the next shape in the order.
            sh = ShapeContainer1.GetNextShape(sender, True)
            ' Select the next shape.
            ShapeContainer1.SelectNextShape(sender, False, True)
        End If
    End Sub
    
    private void shapes_PreviewKeyDown(Shape sender, System.Windows.Forms.PreviewKeyDownEventArgs e)
    {
        Shape sh;
        // Check for the Control and Tab keys.
        if (e.KeyCode == Keys.Tab && e.Modifiers == Keys.Control)
        // Find the next shape in the order.
        {
            sh = shapeContainer1.GetNextShape(sender, true);
            // Select the next shape.
            shapeContainer1.SelectNextShape(sender, false, true);
        }
    }
    
  4. Agregue el código siguiente al procedimiento de evento Button1_PreviewKeyDown:

    Private Sub Button1_PreviewKeyDown(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) _
      Handles Button1.PreviewKeyDown
        ' Check for the Control and Tab keys.
        If e.KeyCode = Keys.Tab And e.Modifiers = Keys.Control Then
            ' Select the first shape.
            RectangleShape1.Select()
        End If
    End Sub
    
    private void button1_PreviewKeyDown(object sender, System.Windows.Forms.PreviewKeyDownEventArgs e)
    {
        // Check for the Control and Tab keys.
        if (e.KeyCode == Keys.Tab & e.Modifiers == Keys.Control)
        // Select the first shape.
        {
            rectangleShape1.Select();
        }
    }
    

Vea también

Tareas

Cómo: Dibujar formas con los controles OvalShape y RectangleShape (Visual Studio)

Cómo: Dibujar líneas con el control LineShape (Visual Studio)

Conceptos

Introducción a los controles de líneas y formas (Visual Studio)

Historial de cambios

Fecha

Historial

Motivo

Julio de 2008

Se ha agregado un tema.

Cambio de características de SP1.