Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. What is a preferable approach to develop a common class that handles multiple identical groupbox?

What is a preferable approach to develop a common class that handles multiple identical groupbox?

Scheduled Pinned Locked Moved Managed C++/CLI
questiondesignperformancehelptutorial
1 Posts 1 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15150778
    wrote on last edited by
    #1

    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 +=
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups