Partilhar via


Como: Habilitar andar com a tecla TAB entre formas (Visual Studio)

Controles de linha e a forma não têm TabStop ou TabIndex Propriedades, mas você ainda poderá habilitar a navegação por TAB entre elas. No exemplo a seguir, pressionando a tecla CTRL e as teclas TAB será guia entre formas; somente da tecla TAB fará entre os botões da guia.

Observação:

Seu computador pode mostrar diferentes nomes ou localizações para alguns dos elementos de interface do usuário do Visual Studio nas instruções a seguir.A edição do Visual Studio que você possui e as configurações que você usa determinam esses elementos.Para obter mais informações, consulte Configurações do Visual Studio.

Para ativar a navegação por TAB entre formas

  1. arrastar três RectangleShape controles e dois Button Controla a partir do Caixa de ferramentas em um formulário.

  2. No Editor de código, add an Imports ou using demonstrativo na parte superior do módulo:

    Imports Microsoft.VisualBasic.PowerPacks
    
    using Microsoft.VisualBasic.PowerPacks;
    
  3. Adicione o seguinte código em um procedimento 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. Adicione o seguinte código no Button1_PreviewKeyDown procedimento de evento:

    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();
        }
    }
    

Consulte também

Tarefas

Como: Desenhar formas com a OvalShape e RectangleShape Controls (Visual Studio)

Como: Desenhar linhas com o controle LineShape (Visual Studio)

Conceitos

Introdução à linha e forma Controls (Visual Studio)

Date

History

Motivo

Julho de 2008

Tópico adicional.

Alteração de recurso do SP1.