|
Bücher,C undC#TrainingsfürProgrammierer c schulungen, C# Schulungen, Bücher über c mit Visual Studio
|
bet | 6/8 | Sana | 20.02.2024 | Hajmi | 1,28 Mb. | | #159175 |
Bog'liq www rkaiser de c-winforms-tutorial
By double-clicking the button on the form, Visual Studio creates the function (the event handler) that will be called when the button is clicked when the program is running:
private: System::Void
button_plus_1_Click(System::Object^ sender,
System::EventArgs^ e)
{
}
In this event handler you then call the corresponding function. In this simple tutorial this is the function plus_1 from the file Header.h.
If this function uses user input, you read it in via a TextBox. In this simple tutorial, it will be a number that is read from the in_TextBox.
If a parameter of the called function does not have type String (the type of the property in_textBox→Text), the string must be converted to the type of the parameter. This is possible with one of the Convert:: functions. The results are to be displayed in the out_textBox. This can be done with the function out_textBox→AppendText. The string that AppendText expects can be created with String::Format. In the first argument (a string) you specify 0 for the first value after the string, 1 for the second and so on.
private: System::Void
button_plus_1_Click(System::Object^ sender,
System::EventArgs^ e)
{
int n = Convert::ToInt32(in_textBox->Text); int result = plus_1(n); out_textBox->AppendText(String::Format("plus_1({0})=
{1}\r\n",n,result));
}
If you enter a number in the input field after starting this program with F5 and then click on the button, the value incremented by 1 is displayed in the output text box:
For each further function whose result is to be displayed, a button is placed on the form and given a suitable name (Name property) and a suitable label (Text property). This function is then called in the associated event handler.
With this all relevant parts of the ??? CppCLR_Winforms_GUI are presented. You can enhance it as you like with additional controls (buttons, menus, etc.). See chapter 2 of mybookfor more information.
|
| |