C# Custom Control Handling

May 24 2013 9:27 AM
 

Dear Colleagues

 

I am really new in c# even thought i am experienced in vb .net. For the first time i have created a form with a vertical split panel. I have already created a custom control with 7 buttons and on the initialization of the main form i have add it on the left panel. I can see my control in design mode and while running the application.

 

My problem is this: i cannot handle the click button event on my custom control. even though when i put a messagebox.show command inside a button click event the message show on runtime. when i try to load another custom control on the second panel of the main form the code passes through the initialization lines

The Consept is really simple.

 

public partial class CtlSideBar : UserControl

    {

public CtlSideBar()

        {        

  InitializeComponent();

        }

private void BtnCount_Click(object sender, EventArgs e)

        {         

var          CountControl = new CtlCounter();

MainFrm.panel2.controls.add(CountControl);

            CountControl.Visible = true;

MessageBox.Show("test");

        }

    }

The above code is written inside the btncount click event of a button on my first control (Its the Sidebar of My application and it its initialized on the main form ). the CountControl will not be shown probably because its not added on the main form. But my problem is that i don't know how to associate the event of the button of first control with the right panel on the main form. ( Line MainFrm.panel2.controls.add(CountControl); its not recognized)

Probably all the above are really simple. Don't Know. But i would appreciate any help given

Thanks in advanced and if there is any misunderstanding because my English is not very good pleade feel free to ask me anything.