rj tubera
rj tubera

Reputation: 757

Tab Control Shares The same buttons Winform

I wonder If it is possible to have fixed number of buttons that is shared by different tab pages. However I don't know how to implement this. Do you guys have any idea.

Heres a screenshot of my gui so that all of you can have a clearer view of what I meant.

1

I want that that the list of Customers, Reservations, and Check In/out will share the buttons search, edit, delete and refresh.

Is it possible? or should I create diff buttons for every tabpage?

is it correct if i do:

private void buttonSearch_Click(object sender, EventArgs e)
{ 
  if(tabpage.SelectedIndex == 1){ then perform action..}
  if(tabpage.SelectedIndex == 2) {then perform action...}
}

Upvotes: 0

Views: 2418

Answers (3)

A G
A G

Reputation: 22587

I feel you should create different buttons for every tab page as each one operates on a different entity. If there is only one set of buttons then you will have to first check which tab page is selected and then do the operation. So you will have one big method doing lots of things.

Plus there would be extra UI code that you will have to write to move the buttons when a tab page is selected.

With different buttons you will have highly cohesive and loosely coupled code. Better design. More maintainable and manageable. Less code.

Upvotes: 0

Bas
Bas

Reputation: 27105

You could put the buttons in a User Control, add some events to the User Control (e.g. SearchClicked, EditClicked, etc.). Put the user control outside of the tabcontrol.

Then when you change tabs (TabIndexChanged), remove event handlers from the previous tab, and add event handlers for the new tab:

    private void tabControl_TabIndexChanged(object sender, EventArgs e)
    {
        UserControl1.EditClicked -= OldEventHandler;
        UserControl1.EditClicked += NewEventHandler;
    }

Upvotes: 1

Dan Byström
Dan Byström

Reputation: 9244

Yes, you can change the .Parent property of the buttons at runtime - but wouldn't it be better to just move the buttons outside the tab control?

Upvotes: 0

Related Questions