次の方法で共有


方法 : 図形間のタブ移動を有効にする (Visual Studio)

ライン コントロールとシェイプ コントロールには、TabStop プロパティおよび TabIndex プロパティはありませんが、コントロール間のタブ移動を有効にすることはできます。 次の例では、Ctrl キーと Tab キーの両方を押すと図形間のタブ移動が実行され、Tab キーのみを押すとボタン間のタブ移動が実行されます。

注意

次の手順で参照している Visual Studio ユーザー インターフェイス要素の一部は、お使いのコンピューターでは名前や場所が異なる場合があります。これらの要素は、使用する Visual Studio のエディションとその設定によって決まります。詳細については、「Visual Studio での開発設定のカスタマイズ」を参照してください。

図形間のタブ移動を有効にするには

  1. ツールボックスから、フォームに 3 つの RectangleShape コントロールおよび 2 つの Button コントロールをドラッグします。

  2. コード エディターで、モジュールの先頭に Imports ステートメントまたは using ステートメントを追加します。

    Imports Microsoft.VisualBasic.PowerPacks
    
    using Microsoft.VisualBasic.PowerPacks;
    
  3. イベント プロシージャに次のコードを追加します。

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

参照

処理手順

方法 : OvalShape コントロールおよび RectangleShape コントロールを使用して図形を描画する (Visual Studio)

方法 : LineShape コントロールを使用して線を描画する (Visual Studio)

概念

ライン コントロールとシェイプ コントロールの概要 (Visual Studio)