GUI and application logic not so strictly separated




Download 1,28 Mb.
bet7/8
Sana20.02.2024
Hajmi1,28 Mb.
#159175
1   2   3   4   5   6   7   8
Bog'liq
www rkaiser de c-winforms-tutorial
JORAYEV.SH, Tavsifnoma F, O`zbеkiston Rеspublikasi (1), 1-mavzu «Talaffuzi og‘ir bolalar bilan ishlash metodikasi» fani, Korrespondensiya (3), Korrespondensiya (3), 3-mavzu.google uchun vaqtincha, 1.1.1, Dunyoqarashning mohiyati1-mustaqil ish, O’rnatilgan tizimlarda rfid-fayllar.org, 1-mustaqil ishi topshirdi D. Egamberdiyev Qabul qildi G`aniyev A, AZIMOVA DURDONA, KAMCHIBEKOVA RAYXONOY KKKK, 7- amaliy ish Mavzu Openssl kutubxonasidan foydalangan holda ma

5. GUI and application logic not so strictly separated


In the version created under 1. to 4. the application logic is strictly separated from the user interface: The access to the user interface with C/CLI is exclusively done in Form1.h. In Header1.h, however, only standard C is used. This has in particular the advantage that one can use this header also in other platforms (e.g. console applications, Qt, Mac).
However, in the early stages of a project, when there is still a lot of experimenting going on, it can be a bit cumbersome if you have to change the calls in another file every time you change a parameter list. And for applications that are not intended to be used for other platforms at all, this strict separation doesn’t help much. This often applies to exercise tasks as well.
This jumping back and forth between different files can be avoided by relaxing the strict separation between the application logic and the user interface by including access to the controls in the header file as well.
Accessing controls in a header file is enabled by inserting
using namespace System;
using namespace System::Windows::Forms;
into the header file at the beginning. Then you can also use the types of the controls in the header file (e.g. as parameters) and include the statements that were in the buttonClick function in Form1.h under 4.
This procedure is implemented in the Header2.h file:
#pragma once using namespace System;
using namespace System::Windows::Forms;
int plus_2(int x)
{ return x + 2;
}
void plus_2_Click(TextBox^ in_textBox, TextBox^ out_textBox)
{
int n = Convert::ToInt32(in_textBox->Text); int result = plus_2(n);
out_textBox->AppendText(String::Format("plus_2({0})=
{1}\r\n", n, result));
}
Here you pass a parameter for the control to the function. Please note that you must specify a ^ after the name of a .NET type (e.g. TextBox, Button). In the function you then address the control under the name of the parameter.
This function can be called when a button is clicked:
private: System::Void
button_plus_1_Click(System::Object^ sender,
System::EventArgs^ e)
{ plus_2_Click(in_textBox, out_textBox);
}

Download 1,28 Mb.
1   2   3   4   5   6   7   8




Download 1,28 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



GUI and application logic not so strictly separated

Download 1,28 Mb.