I have two tabs in a form . The first form has some buttons which are common to the second tab. But there are some additional buttons in the second tab which need to be worked on . I have included the buttons in the second tab .But I am really confused how to make it functional like how do I step in my second tab and write the functions ? Can you help me out . I have class already made for the first tab . I need to include the other tab in that .

Recommended Answers

All 2 Replies

Do you have two tab controls or two tabs on a single tab control? Is there one or two forms?
Not sure what you mean by

I have class already made for the first tab.

Any code needed to manage the controls should be on the form.

I will assume you have a single tab control with two tabs on a single form.

To have a common button on each tab control there are two approaches that I can think of.

1) The simples is to move the common button out of the tab control so that it is always available which ever tab is selected.
To have the button look like it is in the tab control, just re-position it in code after the Initialise() method in the forms constructor.
(i.e. Set its Left and Top properties)

2) The next is to have two button (one in each tab) and attach the same event method to the buttons click events.
Normally the button click event handler is automatically created by double clicking on the button.
However, it is possible to select a method that already exists by first
changing the Properties Window to show events (little lighting button)
then finding the Click event and selecting the existing method from the drop down list.

I hope u have placed the main Tab control on the Main form.

For ur Tab control there is an Event 'SelectedPageChanged';
Use this event,
It ll work every time u click the either tabs.

if(Tabcontrol.SelectedTabPage == searchTabPage)
{
if(objSearch != null)
TabPage.Controls.Add(objSearch);
}

Add this to your code.

commented: nice idea +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.