TabControl events
-
Good evening all, I have a form with a number of controls on it. In particular - some buttons and a 'TabControl' In the form designer, when i double click on a button, i can code an event to fire, like below,
private void button1_Click(object sender, EventArgs e)
{
//some code
}I would like t be able to do the same when the user clicks on one of the tabs of my TabControl, however i can seem to find a way to trigger an event like i do with a button. For example - if i double cick on the tab in the designer view - nothing happens. Can anyone help ? Regards Neil
-
Good evening all, I have a form with a number of controls on it. In particular - some buttons and a 'TabControl' In the form designer, when i double click on a button, i can code an event to fire, like below,
private void button1_Click(object sender, EventArgs e)
{
//some code
}I would like t be able to do the same when the user clicks on one of the tabs of my TabControl, however i can seem to find a way to trigger an event like i do with a button. For example - if i double cick on the tab in the designer view - nothing happens. Can anyone help ? Regards Neil
Check out the events in the properties window for the control. You have click, doubleclick, etc.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Good evening all, I have a form with a number of controls on it. In particular - some buttons and a 'TabControl' In the form designer, when i double click on a button, i can code an event to fire, like below,
private void button1_Click(object sender, EventArgs e)
{
//some code
}I would like t be able to do the same when the user clicks on one of the tabs of my TabControl, however i can seem to find a way to trigger an event like i do with a button. For example - if i double cick on the tab in the designer view - nothing happens. Can anyone help ? Regards Neil
Hi, TabControl.SelectedIndexChanged is the right event for you; you may want to include a switch in its handler if you need to run different code snippets for different tab pages. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
Good evening all, I have a form with a number of controls on it. In particular - some buttons and a 'TabControl' In the form designer, when i double click on a button, i can code an event to fire, like below,
private void button1_Click(object sender, EventArgs e)
{
//some code
}I would like t be able to do the same when the user clicks on one of the tabs of my TabControl, however i can seem to find a way to trigger an event like i do with a button. For example - if i double cick on the tab in the designer view - nothing happens. Can anyone help ? Regards Neil
Has anyone suggested to you yet that you should put a
UserControl
on each tab page that contains that tab page's controls so you can have discreet access to all the controls on a given page?"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Hi, TabControl.SelectedIndexChanged is the right event for you; you may want to include a switch in its handler if you need to run different code snippets for different tab pages. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
Thank you Luc, So can you please give me some guidance as to how i would then use this to make some.....labels or checkboxes appear for instance ? I have trid a few things but it seems quit a dfficult control to use. Thanks Neil
As John pointed out, the easiest way to handle a TabControl in Visual Designer is to create one UserControl per tabpage; i.e. first create the UserControls you want, then create a TabControl on your form and instantiate the UserControls on the individual pages. An alternative, not that popular though, is to create the Controls by run-time code. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
As John pointed out, the easiest way to handle a TabControl in Visual Designer is to create one UserControl per tabpage; i.e. first create the UserControls you want, then create a TabControl on your form and instantiate the UserControls on the individual pages. An alternative, not that popular though, is to create the Controls by run-time code. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
unfortunatley i'm completely new to programming so all that means very little to me. Its my first time trying a tabControl, i have created & tested all my buttons to go on it, i just needed other things to appear on the form when user chose the varius tabs on the form. I'm kind of thinking i've bitten off more than i can chew ? :confused: I'll have a look for infon on 'UserControls' and see what i can find. Many thanks Neil
-
unfortunatley i'm completely new to programming so all that means very little to me. Its my first time trying a tabControl, i have created & tested all my buttons to go on it, i just needed other things to appear on the form when user chose the varius tabs on the form. I'm kind of thinking i've bitten off more than i can chew ? :confused: I'll have a look for infon on 'UserControls' and see what i can find. Many thanks Neil
Hi, You do not need UserControls if they are new to you: you can design a TabControl in Visual Designer without UserControls, just click on the tab to show an individual tab page (you may have to try a couple of times to get the page you want), then fill it as usual. IMO it is easier with UserControls though (only if you are used to them that is). :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
Hi, You do not need UserControls if they are new to you: you can design a TabControl in Visual Designer without UserControls, just click on the tab to show an individual tab page (you may have to try a couple of times to get the page you want), then fill it as usual. IMO it is easier with UserControls though (only if you are used to them that is). :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
Hi Luc, Sorry - i know this is dragging on a bit. I have the tab control functional and populated with my controls already, what i want to do is make some other controls (check boxes etc) appear on the page when the user clicks on a tab. I can code an event if i double click on the page of the tab (in designer) but that doesn't help work. I want the event to run when the user clicks on the tab. It's not the same as clicking on the tab page. Hope this makes sense !
-
Hi Luc, Sorry - i know this is dragging on a bit. I have the tab control functional and populated with my controls already, what i want to do is make some other controls (check boxes etc) appear on the page when the user clicks on a tab. I can code an event if i double click on the page of the tab (in designer) but that doesn't help work. I want the event to run when the user clicks on the tab. It's not the same as clicking on the tab page. Hope this makes sense !
Clicking on any tab fires the SelectedIndexChanged event; so you should add a handler for that event, get the new tab page index from the SelectedIndex property, and act accordingly in your handler's code. I find myself adding a switch statement quite often in such a handler. In order to add a handler, you can use Visual Designer, click the tab control, get its properties, get the events pane, and double-click the row for SelectedIndexChanged. That will create an empty handler, and generate the wiring for it. Or you can add it just by editing the code... (everything Designer does, you can code yourself also). :) ?
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
modified on Wednesday, December 17, 2008 5:45 PM