更新:2007 年 11 月
Line 和 Shape 控件没有 TabStop 或 TabIndex 属性,但您仍可以使用 Tab 键在它们之间切换。在下面的示例中,同时按 Ctrl 和 Tab 键将在形状之间切换;仅按 Tab 键将在按钮之间切换。
| .gif) 说明: | 
|---|
| 以下说明中的某些 Visual Studio 用户界面元素在计算机上出现的名称或位置可能会不同。您安装的 Visual Studio 版本以及使用的设置决定了这些元素。有关更多信息,请参见 Visual Studio 设置。 | 
使用 Tab 键在形状之间切换
- 从“工具箱”中将三个 RectangleShape 控件和两个 Button 控件拖到窗体中。 
- 在“代码编辑器”中,将 Imports 或 using 语句添加到模块的顶部: - Imports Microsoft.VisualBasic.PowerPacks- using Microsoft.VisualBasic.PowerPacks;
- 将下面的代码添加到事件过程中: - 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); } }
- 将下面的代码添加到 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)
概念
Line 和 Shape 控件简介 (Visual Studio)
修订记录
| 日期 | 修订 | 原因 | 
|---|---|---|
| 2008 年 7 月 | 新增主题。 | SP1 功能更改。 |