TabControl with derived TabPage class

Richard Kucia <[email protected]> Tue, 3 Jul 2007 21:16:59 +0000
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <070320072116.25759.468ABCC9000E97130000649F21602807480E070C9A05069D@att.net>
As an experiment, I created an app in which there is no design-time info on the form. All the controls are defined by a config file. The controls are instantiated and their properties are set at run-time by my own code, not via InitializeComponents.

In order to play with some fancy positioning features, I created about 10 classes derived from of the usual Windows controls. So I have a DynamicLabel, DynamicGroupBox, DynamicTabControl, DynamicTabPage, etc. Other than a couple of extra properties and methods, there's nothing much in these derived classes. Nothing in the standard TabPage is overridden.

Public Class DynamicTabPage
Inherits TabPage
Implements IDynamicControl

While testing this stuff, I may have found an odd bug with the TabControl and/or TabPage.

I created a multi-level hierarchy of control on the form like this:

DynamicTabControl outer
  DynamicTabPage prj
    misc controls
  DynamicTabPage act
    DynamicTextBox name
    DynamicTextBox desc
    DynamicTabControl inner
      DynamicTabPage prp
        labels & combo boxes
      DynamicTabPage hom
        textboxes
      DynamicTabPage def
        textboxes
  DynamicTabPage pnt
    more typical stuff

The basic idea is that there is one outer tab control, and in it the tab page "act" contains an inner tab control.

What is happening is this: I select tab page "act" and within it I further select tab page "hom". Then I click the tab for page "pnt". What I expect to see is the contents of the "pnt" page. When I click "act" I expect to return to the "act" page, including having the inner tab control resume its previous state. What I see is very strange: the tab on the inner control shows that "hom" is selected, but the *contents* of that page is actually the contents of the "prp" page! I can manually click the tabs of the inner tab control and get the right contents to appear. The problem is specifically related to when the tab control is refreshing.

Furthermore, if I navigate around and get the "hom" page to appear, then if I click on it, the "prp" page appears.

And also -- the TAB key seems to blow right on past the end-of-page. The focus keeps on advancing to my controls on other pages -- even though their pages never are shown.

And to wrap things up, when I switch my implementation to use a true .Net TabPage, things resume working correctly again.

So either it's not possible for a TabControl to work with a class derived from a TabPage, or I need some assistance in getting this to work. Thanks for the help.

Rick Kucia