Esempio n. 1
0
            public override bool Layout(object container, LayoutEventArgs layoutEventArgs)
            {
                // fetch the display rectangle of the TabStrip.  This is typically
                // the TabStrip.ClientRectangle - TabStrip.Padding
                Rectangle displayRect = tabStrip.DisplayRectangle;

                // the next location to place the item, start off at the upper left hand corner.
                Point nextLocation = displayRect.Location;

                for (int i = 0; i < tabStrip.Items.Count; i++)
                {
                    ToolStripItem item = tabStrip.Items[i] as ToolStripItem;
                    if (!item.Available)
                    {
                        continue;
                    }
                    Tab currentTab = item as Tab;

                    tabStrip.SetItemLocation(item, new Point(nextLocation.X, nextLocation.Y));

                    if (item.AutoSize)
                    {
                        if (currentTab != null)
                        {
                            //this is a tab, make sure it stretches from top->bottom
                            item.Size = new Size(item.GetPreferredSize(displayRect.Size).Width, displayRect.Height);
                        }
                        else
                        {
                            //this not tab, keep it it's preferred width/height.
                            item.Size = item.GetPreferredSize(displayRect.Size);
                        }
                    }

                    // advance "nextLocation".
                    // This could simply be
                    //      nextLocation.X += item.Width - tabStrip.TabOverlap;
                    // ...but we're fancier than that.
                    // if the next thing isnt a tab, we dont want to overlap it.


                    Tab nextTab = (i + 1 < tabStrip.Items.Count) ? tabStrip.Items[i + 1] as Tab : null;
                    if (currentTab != null && nextTab != null)
                    {
                        // we are a Tab, and the next thing is a Tab
                        // overlap
                        nextLocation.X += item.Width - tabStrip.TabOverlap;
                    }
                    else
                    {
                        nextLocation.X += item.Width;
                    }
                }
                return(tabStrip.AutoSize);
            }
Esempio n. 2
0
            public override bool Layout(object container, LayoutEventArgs layoutEventArgs)
            {
                // fetch the display rectangle of the TabStrip.  This is typically
                // the TabStrip.ClientRectangle - TabStrip.Padding
                Rectangle displayRect = tabStrip.DisplayRectangle;

                // the next location to place the item, start off at the upper left hand corner.
                Point nextLocation = displayRect.Location;

                for (int i = 0; i < tabStrip.Items.Count; i++)
                {
                    ToolStripItem item = tabStrip.Items[i] as ToolStripItem;

                    // Set the item's location as specified by nextLocation
                    tabStrip.SetItemLocation(item, new Point(nextLocation.X, nextLocation.Y));

                    // if the item is AutoSized, set it to the preferred size
                    if (item.AutoSize)
                    {
                        // use the preferredSize.Width, use the DisplayRectangle.Height for the height
                        Size preferredSize = item.GetPreferredSize(displayRect.Size);
                        preferredSize.Height = displayRect.Height;
                        item.Size            = preferredSize;
                    }
                    nextLocation.X += item.Width - tabStrip.TabOverlap;
                }
                return(tabStrip.AutoSize);
            }