Demonstra Passo a passo: Depuração de um formulário do Windows
This topic applies to:
Edition |
Visual Basic |
C# |
C++ |
Web Developer |
---|---|---|---|---|
Express |
Managed only |
|||
Pro, Premium e Ultimate |
Managed only |
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
Sobre o arquivo menu, escolha nova e clique em projeto.
The New Project dialog box appears.
No painel Project Types, abra o Visual Basic, C# Visual, ou Visual C++ nó, em seguida,
Visual Basic ou C# Visual, selecione o Windows nó, em seguida, selecione Aplicativo de formulário do Windows na modelos de painel.
Para Visual C++, selecione o CLR nó, em seguida, selecione Aplicativo de formulário do Windows na modelos de painel..
In the Templates pane, select Windows Application.
In the Name box, give the project a unique name (for example, Walkthrough_SimpleDebug).
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.
Sobre o Exibir menu, selecione Toolbox.
The Toolbox opens. For more information, see Toolbox.
In the Toolbox, click on the Button control and drag the control to the Form design surface. Drop the button on the form.
In the Toolbox, click on the TextBox control and drag the control to the Form design surface. Drop the TextBox on the form.
On the form design surface, double-click the button.
This takes you to the code page. O cursor deve estar em button1_Click.
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!";
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
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çã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.
Diante do Debug menu, escolha Iniciar.
The Windows Form starts running.
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.
No Debug menu, escolha Windows, em seguida, Watche clique em Watch1.
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:
""
Sobre o Debug menu, escolha Step Into.
The value of textBox1.Text changes in the Watch1window to:
Button was clicked!
Sobre o Depurar menu, escolha continuar para continuar a depuração do programa.
On the Windows Form, click the button again.
Visual Studio breaks execution again.
Click on the red dot that represents the breakpoint.
This removes the breakpoint from your code.
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
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!";
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.
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.
In the Available Processes pane, find the process name (Walkthrough_SimpleDebug.exe) in the Process column and click it.
Click the Attach button.
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
Outros recursos
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. |