Sharing a component across multiple tabs

G

giles.thomas

Hi,

I have an application where multiple TabPages (within the same
TabControl) need to contain the same components; switching tabs changes
the data source feeding into the components. I guess this is a problem
a lot of people have solved in the past, but I can't seem to get it to
work elegantly.

In my current implementation, each time I receive a "Selected" event
from the TabControl I switch over my data source, then add my data
panel to the newly-selected tab (which automatically removes it from
the previous tab). This works reasonably well, but the data grid
"flickers" irritatingly - I suspect because of the reparenting.

I have tried making the TabControl and the data panel children of the
same parent Panel, laid out so that the tabs abut the data panel, and
simply changing the data source when the tabs change. This avoids the
flickering problem - but unfortunately the 3D border of the TabPanel is
very visible, so it's obvious that the data panel is not on the
TabControl. If I could switch off the 3D border, this could look OK,
but I can't find any way to do that.

My final attempt was again to put the TabControl and the data panel on
the same parent Panel, but this time making sure that the data panel
was on top of the TabControl in the Z-order, and then listening for
Resize events from the TabControl and handling them by resizing the
data panel so that it precisely obscures the TabPanel. This *almost*
works, but (a) the resizing happens a bit too slowly, and is very
visible to the user, and (b) it feels really really hacky :)

There *must* be a better way of doing this, can anyone help me out?


Cheers,

Giles
 
G

GhostInAK

Hello giles,

You seem really stuck on the TabControl. Any particular reason? If the
actual display elements are not changing.. but rather just the data in the
elements, then a TabControl may not be your best option. You might instead
consider toolbar buttons which would corrospond to your current tabs.. each
button could then stay depressed while that source was active.. You might
also consider a menu control similar to Outlook's (the one where you can
drop down your folder list when its hidden). A simple listbox or listview
would serve well also (add a little custom drawing to make em pretty).

If you are bound and determined to use a tab control in this manner (which
will always be hacky) you may want to stick with your current attempt (reparenting)
and look at the Win32 API function LockWindowUpdate().

-Boo
 
G

giles.thomas

Hi there, thanks for the reply!

Sadly, I have to use the TabControl - our users expect it as a result
of the UI choices in older applications.

I tried using the LockWindowUpdate call as you suggest, and it
certainly did reduce the flicker - indeed, I think it might have
eliminated that amount of it that was due to reparenting the data
panel. However, there was still enough to be annoying.

I'm beginning to suspect I'm going to have to override the TabControl's
drawing functionality, so that I can just put a TabControl next to the
data panel, but make it look as if it is the parent. Are there any
good resources out there that I could use to learn how to override .NET
component's redraw methods?


Regards,

Giles
 
G

GhostInAK

Hello giles,

how about making a tab control that is only as tall (.Height) as the tabs
themselves.. then place your input control below it.. You might have to fixup
the borders a little bit.. but you wouldnt have any flickering.

-Boo
 
G

giles.thomas

Hi there, sorry for being so slow to reply... I did try the tab control
just as you suggested; fixing up the borders did prove problematic,
though, so I passed the problem on to one of my colleagues, a .NET guru
who had the idea of using the SetStyle method on the TabPage. He set
the style to True for the flags AllPaintingInWmPaint, DoubleBuffer, and
UserPaint, and this fixed the problem perfectly.


Regards,

Giles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top