Demonstra Passo a passo: Depuração de um formulário do Windows

This topic applies to:

Edition

Visual Basic

C#

C++

Web Developer

Express

O tópico é aplicável O tópico é aplicável

Managed only

O tópico é aplicável

Pro, Premium e Ultimate

O tópico é aplicável O tópico é aplicável

Managed only

O tópico é aplicável

A Windows Form is one of the most common managed applications. A Windows Form creates a standard Windows application. Você pode concluir esta explicação passo a passo usando Visual Basic, C# ou C++.

First, you must close any open solutions.

To prepare for this walkthrough

  • If you already have an open solution open, close it. (Sobre o arquivo menu, selecione Close Solution.)

Create a New Windows Form

Next, you will create a new Windows Form.

To create the Windows form for this walkthrough

  1. Sobre o arquivo menu, escolha nova e clique em projeto.

    The New Project dialog box appears.

  2. No painel Project Types, abra o Visual Basic, C# Visual, ou Visual C++ nó, em seguida,

    1. Visual Basic ou C# Visual, selecione o Windows nó, em seguida, selecione Aplicativo de formulário do Windows na modelos de painel.

    2. Para Visual C++, selecione o CLR nó, em seguida, selecione Aplicativo de formulário do Windows na modelos de painel..

  3. In the Templates pane, select Windows Application.

  4. In the Name box, give the project a unique name (for example, Walkthrough_SimpleDebug).

  5. Click OK.

    Visual Studio creates a new project and displays a new form in the Windows Forms designer. For more information, see Windows Forms Designer.

  6. Sobre o Exibir menu, selecione Toolbox.

    The Toolbox opens. For more information, see Toolbox.

  7. In the Toolbox, click on the Button control and drag the control to the Form design surface. Drop the button on the form.

  8. In the Toolbox, click on the TextBox control and drag the control to the Form design surface. Drop the TextBox on the form.

  9. On the form design surface, double-click the button.

    This takes you to the code page. O cursor deve estar em button1_Click.

  10. Na função button1_Click., adicione o seguinte código:

    ' Visual Basic
    textBox1.Text = "Button was clicked!"
    
    // C#
    textBox1.Text = "Button was clicked!";
    
    // C++
    textBox1->Text = "Button was clicked!";
    
  11. Sobre o Build menu, selecione Build Solution.

    The project should build with no errors.

Debug Your Form

Now, you are ready to begin debugging.

To debug the Windows Form created for this walkthrough

  1. In the source window, click the left margin on the same line as the text you added:

    ' Visual Basic
    textBox1.Text = "Button was clicked!"
    
    // C#
    textBox1.Text = "Button was clicked!";
    
    // C++
    textBox1->Text = "Button was clicked!";
    

    A red dot appears and the text on the line is highlighted in red. The red dot represents a breakpoint. For more information, see Breakpoints. When you run the application under the debugger, the debugger will break execution at that location when the code is hit. You can then view the state of your application and debug it.

    ObservaçãoObservação

    Você também pode direito qualquer linha de código, aponte para ponto de interrupçãoe em seguida, clique em Insert Breakpoint para adicionar um ponto de interrupção na linha.

  2. Diante do Debug menu, escolha Iniciar.

    The Windows Form starts running.

  3. On the Windows Form, click the button you added.

    In Visual Studio, this takes you to the line where you set your breakpoint on the code page. This line should be highlighted in yellow. You can now view the variables in your application and control its execution. Your application has now stopped executing, waiting for an action from you.

  4. No Debug menu, escolha Windows, em seguida, Watche clique em Watch1.

  5. In the Watch1 window, click on a blank row. No nome coluna, tipo de textBox1.Text (se você estiver usando Visual Basic, C# Visual ou j#) ou textBox1->Text (se você estiver usando C++), pressione ENTER.

    The Watch1 window shows the value of this variable in quotation marks as:

    ""
    
  6. Sobre o Debug menu, escolha Step Into.

    The value of textBox1.Text changes in the Watch1window to:

    Button was clicked!
    
  7. Sobre o Depurar menu, escolha continuar para continuar a depuração do programa.

  8. On the Windows Form, click the button again.

    Visual Studio breaks execution again.

  9. Click on the red dot that represents the breakpoint.

    This removes the breakpoint from your code.

  10. On the Debug menu, choose Stop Debugging.

Anexar ao seu aplicativo de formulário do Windows para depuração

Em Visual Studio, você pode anexar um depurador a um processo em execução. If you are using an Express Edition, this feature is not supported.

Para anexar o aplicativo de formulário do Windows para depuração

  1. In the project you created above, click in the left margin to once again set a breakpoint at the line you added:

    ' Visual Basic
    textBox1.Text = "Button was clicked!"
    
    // C#
    textBox1.Text = "Button was clicked!"
    
    // C++
    textBox1->Text = "Button was clicked!";
    
  2. Sobre o Debug menu, selecione 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. Sobre o Debug menu, selecione Attach to Process. (Este comando também está disponível no Ferramentas menu.)

    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.

Consulte também

Conceitos

Segurança do Depurador

Outros recursos

Depurando código gerenciado

Histórico de alterações

Date

History

Motivo

Dezembro de 2010

Adicionada uma nota que descreve o método alternativo pelo qual você pode inserir um ponto de interrupção usando o menu de contexto.

Comentários do cliente.