// called by tab strip after control has been added..
        void TabPostCreate(TabStrip t, Control ctrl , int i)
        {
            // now we can do the configure of it, with the knowledge the tab has the right size
            int displaynumber = (int)t.Tag;                         // tab strip - use tag to remember display id which helps us save context.

            if (ctrl is UserControlLog)
            {
                UserControlLog sc = ctrl as UserControlLog;
                sc.Text = "Log";
                sc.Init(_discoveryForm, displaynumber);
                sc.AppendText(_discoveryForm.LogText, _discoveryForm.theme.TextBlockColor);
            }
            else if (ctrl is UserControlStarDistance)
            {
                UserControlStarDistance sc = ctrl as UserControlStarDistance;
                sc.Text = "Stars";
                sc.Init(_discoveryForm, displaynumber);
                if (lastclosestsystems != null)           // if we have some, fill in this grid
                    sc.FillGrid(lastclosestname, lastclosestsystems);
            }
            else if (ctrl is UserControlMaterials)
            {
                UserControlMaterials ucm = ctrl as UserControlMaterials;
                ucm.OnChangedCount += MaterialCommodityChangeCount;
                ucm.OnRequestRefresh += MaterialCommodityRequireRefresh;
                ucm.Init(_discoveryForm, displaynumber);
                ucm.LoadLayout();
                ucm.Text = "Materials";
                if (userControlTravelGrid.GetCurrentHistoryEntry != null)
                    ucm.Display(userControlTravelGrid.GetCurrentHistoryEntry.MaterialCommodity.Sort(false));
            }
            else if (ctrl is UserControlCommodities)
            {
                UserControlCommodities ucm = ctrl as UserControlCommodities;
                ucm.Init(_discoveryForm, displaynumber);
                ucm.OnChangedCount += MaterialCommodityChangeCount;
                ucm.OnRequestRefresh += MaterialCommodityRequireRefresh;
                ucm.LoadLayout();
                ucm.Text = "Commodities";
                if (userControlTravelGrid.GetCurrentHistoryEntry != null)
                    ucm.Display(userControlTravelGrid.GetCurrentHistoryEntry.MaterialCommodity.Sort(true));
            }
            else if (ctrl is UserControlLedger)
            {
                UserControlLedger ucm = ctrl as UserControlLedger;
                ucm.Init(_discoveryForm, displaynumber);
                ucm.LoadLayout();
                ucm.Text = "Ledger";
                ucm.OnGotoJID += GotoJID;
                ucm.Display(_discoveryForm.history.materialcommodititiesledger);
            }
            else if (ctrl is UserControlJournalGrid)
            {
                UserControlJournalGrid ucm = ctrl as UserControlJournalGrid;
                ucm.Init(_discoveryForm, displaynumber);
                ucm.LoadLayout();
                ucm.Text = "Journal";
                ucm.Display(_discoveryForm.history);
                ucm.NoHistoryIcon();
                ucm.NoPopOutIcon();
            }
            else if (ctrl is UserControlTravelGrid)
            {
                UserControlTravelGrid ucm = ctrl as UserControlTravelGrid;
                ucm.Init(_discoveryForm, displaynumber);
                ucm.NoHistoryIcon();
                ucm.NoPopOutIcon();
                ucm.LoadLayout();
                ucm.Text = "History";
                ucm.Display(_discoveryForm.history);
                ucm.NoHistoryIcon();
                ucm.NoPopOutIcon();
            }
            else if (ctrl is UserControlScreenshot)
            {
                UserControlScreenshot ucm = ctrl as UserControlScreenshot;
                ucm.Init(_discoveryForm, displaynumber);
                ucm.LoadLayout();
                ucm.Text = "Screen Shot";
            }
            else if (ctrl is UserControlStats)
            {
                UserControlStats ucm = ctrl as UserControlStats;
                ucm.Init(_discoveryForm, displaynumber);
                ucm.LoadLayout();
                ucm.Text = "Statistics";
                ucm.SelectionChanged(userControlTravelGrid.GetCurrentHistoryEntry, _discoveryForm.history);
            }
            else if (ctrl is UserControlScan)
            {
                UserControlScan ucm = ctrl as UserControlScan;
                ucm.Init(_discoveryForm, displaynumber);
                ucm.LoadLayout();
                ucm.Text = "Scan";
                ucm.Display(userControlTravelGrid.GetCurrentHistoryEntry, _discoveryForm.history);
            }

            System.Diagnostics.Debug.WriteLine("And theme {0}", i);
            _discoveryForm.theme.ApplyToControls(t);
        }
 // pop out clicked
 void TabPopOut(TabStrip t, int i)
 {
     PopOut((PopOuts)i);
 }
        // called by tab strip when selected index changes.. create a new one.. only create.
        Control TabCreate(TabStrip t, int si)
        {
            PopOuts i = (PopOuts)si;

            if (i == PopOuts.Log)
                return new UserControlLog();
            else if (i == PopOuts.NS)
                return new UserControlStarDistance();
            else if (i == PopOuts.Materials)
                return new UserControlMaterials();
            else if (i == PopOuts.Commodities)
                return new UserControlCommodities();
            else if (i == PopOuts.Ledger)
                return new UserControlLedger();
            else if (i == PopOuts.Journal)
                return new UserControlJournalGrid();
            else if (i == PopOuts.TravelGrid)
                return new UserControlTravelGrid();
            else if (i == PopOuts.ScreenShot)
                return new UserControlScreenshot();
            else if (i == PopOuts.Statistics)
                return new UserControlStats();
            else if (i == PopOuts.Scan)
                return new UserControlScan();
            else
                return null;
        }
 void TabConfigure(TabStrip t, int displayno)
 {
     t.Images = popoutbitmaps;
     t.ToolTips = popouttooltips;
     t.Tag = displayno;             // these are IDs for purposes of identifying different instances of a control.. 0 = main ones (main travel grid, main tab journal). 1..N are popups
     t.OnRemoving += TabRemoved;
     t.OnCreateTab += TabCreate;
     t.OnPostCreateTab += TabPostCreate;
     t.OnPopOut += TabPopOut;
 }
 // called by tab strip when a control is removed
 void TabRemoved(TabStrip t, Control c )
 {
     UserControlCommonBase uccb = c as UserControlCommonBase;
     uccb.Closing();
 }
 // pop out clicked
 void TabPopOut(TabStrip t, int i)
 {
     PopOut((PopOuts)(i+1));
 }