- Local time
- Tomorrow, 07:35
- Joined
- Jan 20, 2009
- Messages
- 12,832
A much simpler technique to conditionally hiding controls is by using a Tab Control. It requires hardly any code at all. I will describe an example where controls are conditionally displayed being triggered by a master control getting the focus. Similar principles can be applied for other purposes.
Place all the controls that are to be made visible for a particular master control on a page of the TabControl. Where a child control needs to be displayed on more the one (but not all) of the pages, simply copy and paste it onto the extra pages. It will need a different name on each page but it can have the same ControlSource.
Configure the properties of the TabControl (not the Pages) so that it isn't apparent by setting its Style to None (removes the little tabs at the top), the BorderStyle and BackStyle to Transparent. Now the TabControl can cover the whole form if you like without occluding the other controls on the form itself. (Of course you will have to make sure you don't locate the Page's controls in the same place of those on the form.)
The TabContrl Page to be displayed can be selected by changing the Value property of the TabControl to the required Pages index. Let's call the TabControl something like "ConditionalControls".
The appropriate ConditionalControls page can be configured in the Tag Property of the master controls. Use this one line function in the GotFocus Event of each of the master controls.
That is all there is to it.
Place all the controls that are to be made visible for a particular master control on a page of the TabControl. Where a child control needs to be displayed on more the one (but not all) of the pages, simply copy and paste it onto the extra pages. It will need a different name on each page but it can have the same ControlSource.
Configure the properties of the TabControl (not the Pages) so that it isn't apparent by setting its Style to None (removes the little tabs at the top), the BorderStyle and BackStyle to Transparent. Now the TabControl can cover the whole form if you like without occluding the other controls on the form itself. (Of course you will have to make sure you don't locate the Page's controls in the same place of those on the form.)
The TabContrl Page to be displayed can be selected by changing the Value property of the TabControl to the required Pages index. Let's call the TabControl something like "ConditionalControls".
The appropriate ConditionalControls page can be configured in the Tag Property of the master controls. Use this one line function in the GotFocus Event of each of the master controls.
Code:
Private Function ShowConditionalControls()
Me.ConditionalControls = Me.ActiveControl.Tag
End Function