你可以完成此演练使用 Visual Basic 中, C#,或 c + +。

首先,您必须关闭任何打开的解决方案。

准备此次演练

  • (在文件菜单中,选择关闭解决方案。)

创建新的 Windows 窗体

接下来,您将创建一个新的 Windows 窗体。

若要创建用于本演练中的 Windows 窗体

  1. 上文件菜单中,选择新建然后单击项目。

    此时将出现“新建项目”对话框。

  2. 在项目类型窗格中,打开Visual Basic, Visual C# ,或Visual c + + 节点,然后

    1. Visual Basic 或 Visual C#,选择Windows 桌面 > Windows 窗体应用。

    2. 对于 Visual c + + 中,选择Windows 桌面应用程序。

  3. 在中名称框中,为项目指定唯一名称 (例如,Walkthrough_SimpleDebug)。

  4. 单击 “确定”。

    Windows 窗体设计器。

  5. 上视图菜单中,选择工具箱。

    工具箱。

  6. 将按钮拖动窗体上。

  7. Drop文本框中窗体上。

  8. 在窗体设计图面上,双击该按钮。

    光标应位于button1_Click

  9. 在 button1_Click 函数中,添加以下代码:

    C#
    textBox1.Text = "Button was clicked!";
    
    C++
    textBox1->Text = "Button was clicked!";
    
  10. 在“生成”菜单上,选择“生成解决方案”。

    该项目应顺利生成,没有错误。

调试窗体

现在,已准备好开始调试。

若要调试在本演练中创建的 Windows 窗体

  1. 在源窗口中,单击你添加的文本的同一行的左侧的空白:

    C#
    textBox1.Text = "Button was clicked!";
    
    C++
    textBox1->Text = "Button was clicked!";
    

    然后您可以查看应用程序的状态并调试它。

     备注

    此外可以右键单击任意行的代码中,指向断点,然后单击插入断点该行上添加断点。

  2. 在“调试”菜单上选择“启动”。

    Windows 窗体开始运行。

  3. 在 Windows 窗体中,单击添加按钮。

    你的应用程序现已停止执行,等待您的操作。

  4. 上调试菜单中,选择Windows,然后观看,然后单击Watch1。

  5. 在中名称列中,键入textBox1.Text(如果使用 Visual Basic 或 Visual C#) 或textBox1->Text(如果使用 c + +),然后按 ENTER。

    监视 1窗口会显示此变量的值与引号中:

    ""

  6. 在“调试”菜单上选择“逐语句”。

    TextBox1.Text 的更改的值监视 1窗口:

    Button was clicked!

  7. 上调试菜单中,选择继续以继续进行调试您的程序。

  8. 在 Windows 窗体中,再次单击按钮。

    Visual Studio 将中断再次执行。

  9. 单击表示断点的红点。

    这将在代码中移除该断点。

  10. 在“调试”菜单上,选择“停止调试”。

附加到 Windows 窗体应用程序进行调试

如果使用 Express Edition,不支持此功能。

若要将附加到 Windows 窗体应用程序进行调试

  1. 在上述步骤中创建的项目中,单击左侧边距处来再一次所添加的行处设置断点:

    C#
    textBox1.Text = "Button was clicked!";
    
    C++
    textBox1->Text = "Button was clicked!";
    
    
  2. On the Debug menu, select Start Without Debugging.

    The Windows Form starts running under Windows, just as if you had double-clicked its executable. The debugger is not attached.

  3. On the Debug menu, select Attach to Process. (This command is also available on the Toolsmenu.)

    The Attach to Process dialog box appears.

  4. In the Available Processes pane, find the process name (Walkthrough_SimpleDebug.exe) in the Process column and click it.

  5. Click the Attach button.

  6. In your Windows Form, click the one and only button.

    The debugger breaks execution of the Windows Form at the breakpoint.

See Also

相关文章:

  • 2021-10-02
  • 2021-12-19
  • 2021-11-07
  • 2022-12-23
  • 2022-01-06
  • 2021-12-27
  • 2022-12-23
  • 2022-01-12
猜你喜欢
  • 2021-12-09
  • 2022-01-08
  • 2022-12-23
  • 2022-03-01
  • 2021-11-07
  • 2022-12-23
  • 2022-01-13
相关资源
相似解决方案