Como: ativar a navegação por TAB entre formas (Visual Studio)

Controles de linha e forma não têm TabStop ou TabIndex propriedades, mas você ainda pode ativar a navegação por TAB entre elas.No exemplo a seguir, pressionar as teclas TAB e tanto o CTRL será guia entre formas. somente da tecla TAB será guia entre os botões.

ObservaçãoObservaçã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 de Visual Studio.

Para ativar a navegação por TAB entre formas

  1. Arraste três RectangleShape controles e dois Button controla a partir do caixa de ferramentas a um formulário.

  2. No O Editor de código, adicionar um Imports ou using instrução 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 na 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 os controles de RectangleShape (Visual Studio) e o OvalShape

Como: desenhar linhas com o controle de LineShape (Visual Studio)

Conceitos

Introdução à linha e controles Shape (Visual Studio)