What is a preferable approach to develop a common class that handles multiple identical groupbox?
-
Sorry if my question is unclear, but I shall explain a bit more in the following. Suppose I am making a software to show ONLY 2 employee information (i.e. Bob and Tim), and my implementation method is to create 2 identical group box. Each of this groupbox will have the same UI elements , textbox, checkbox, label and buttons. In order to reduce duplicated codes , I want to create a common class for this groupbox. Will this work? Would there be memory leaks? I did some google research and found something about using smart pointers instead of gcnew'ing a pointer, is it relevant to prevent memory leaks? Thank you very much for reading, i appreciate any constructive help /example code to get this code properly working! common_employee_groupbox.h
#pragma once
ref class common_employee_groupbox
{
private: System::Windows::Forms::CheckBox^ _cb_isAbsent = gcnew (System::Windows::Forms::CheckBox^ ); //IS this correct way to declare?
private: System::Windows::Forms::CheckBox^ _cb_isOverTime gcnew (System::Windows::Forms::CheckBox^ ); //IS this correct way to declare?private: System::Windows::Forms::TextBox^ _tb_employeeName gcnew (System::Windows::Forms::TextBox^ ); //IS this correct way to declare?
private: System::Windows::Forms::TextBox^ _tb_employeeSalary gcnew (System::Windows::Forms::TextBox^ ); //IS this correct way to declare?private: System::Windows::Forms::Button^ _btn_increaseSalary gcnew (System::Windows::Forms::Button^ ); //IS this correct way to declare?
private: System::Windows::Forms::Button^ _btn_decreaseSalary gcnew (System::Windows::Forms::Button^ ); //IS this correct way to declare?public:
common_employee_groupbox(
System::Windows::Forms::CheckBox^ cb_isAbsent,
System::Windows::Forms::CheckBox^ cb_isOverTime,System::Windows::Forms::TextBox^ tb\_employeeName, System::Windows::Forms::TextBox^ tb\_employeeSalary, System::Windows::Forms::Button^ btn\_increaseSalary, System::Windows::Forms::Button^ btn\_decreaseSalary
) {
_cb_isAbsent = cb_isAbsent;
_cb_isOverTime= cb_isOverTime;
_tb_employeeName= tb_employeeName;
_tb_employeeSalary= tb_employeeSalary;
_btn_increaseSalary= btn_increaseSalary;
_btn_decreaseSalary= btn_decreaseSalary;\_btn\_increaseSalary->Click += gcnew System::EventHandler(this,&common\_employee\_groupbox::increaseSalary\_Click); //**IS this correct way to declare?** \_btn\_decreaseSalary->Click +=