⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabcontrol.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 5 页
字号:
                PageDragStart(this, e);
        }

        public virtual void OnPageDragMove(MouseEventArgs e)
        {
            // Has anyone registered for the event?
            if (PageDragMove != null)
                PageDragMove(this, e);
        }

        public virtual void OnPageDragEnd(MouseEventArgs e)
        {
            // Has anyone registered for the event?
            if (PageDragEnd != null)
                PageDragEnd(this, e);
        }

        public virtual void OnPageDragQuit(MouseEventArgs e)
        {
            // Has anyone registered for the event?
            if (PageDragQuit != null)
                PageDragQuit(this, e);
        }
        
        public virtual void OnDoubleClickTab(TabPage page)
        {
            // Has anyone registered for the event?
            if (DoubleClickTab != null)
                DoubleClickTab(this, page);
        }

        protected virtual void OnCloseButton(object sender, EventArgs e)
        {
            OnClosePressed(EventArgs.Empty);
        }

        protected virtual void OnLeftArrow(object sender, EventArgs e)
        {
            // Set starting page back one
            _startPage--;

            _recalculate = true;
            Invalidate();
        }
	
        protected virtual void OnRightArrow(object sender, EventArgs e)
        {
            // Set starting page forward one
            _startPage++;

            _recalculate = true;
            Invalidate();
        }

        protected virtual void DefineFont(Font newFont)
        {
            // Use base class for storage of value
            base.Font = newFont;
	
            // Update internal height value using Font
            _textHeight = newFont.Height;

            // Is the font height bigger than the image height?
            if (_imageHeight >= _textHeight)
            {
                // No, do not need extra spacing around the image to fit in text
                _imageGapTopExtra = 0;
                _imageGapBottomExtra = 0;
            }
            else
            {
                // Yes, need to make the image area bigger so that its height calculation
                // matchs that height of the text
                int extraHeight = _textHeight - _imageHeight;

                // Split the extra height between the top and bottom of image
                _imageGapTopExtra = extraHeight / 2;
                _imageGapBottomExtra = extraHeight - _imageGapTopExtra;
            }
        }

        protected virtual void DefineBackColor(Color newColor)
        {
            base.BackColor = newColor;

            // Calculate the modified colors from this base
            _backLight = ControlPaint.Light(newColor);
            _backLightLight = ControlPaint.LightLight(newColor);
            _backDark = ControlPaint.Dark(newColor);
            _backDarkDark = ControlPaint.DarkDark(newColor);

            _backIDE = ColorHelper.TabBackgroundFromBaseColor(newColor);
        }
		
        protected virtual void DefineButtonImages()
        {
            ImageAttributes ia = new ImageAttributes();

            ColorMap activeMap = new ColorMap();
            ColorMap inactiveMap = new ColorMap();

            // Define the color transformations needed
            activeMap.OldColor = Color.Black;
            activeMap.NewColor = _buttonActiveColor;
            inactiveMap.OldColor = Color.White;
            inactiveMap.NewColor = _buttonInactiveColor;

            // Create remap attributes for use by button
            ia.SetRemapTable(new ColorMap[]{activeMap, inactiveMap}, ColorAdjustType.Bitmap);

            // Pass attributes to the buttons
            _leftArrow.ImageAttributes = ia;
            _rightArrow.ImageAttributes = ia;
            _closeButton.ImageAttributes = ia;
        }

        protected virtual void SetAppearance(VisualAppearance appearance)
        {
            switch(appearance)
            {
                case VisualAppearance.MultiForm:
                case VisualAppearance.MultiBox:
                    _shrinkPagesToFit = true;					// shrink tabs to fit width
                    _positionAtTop = false;						// draw tabs at bottom of control
                    _showClose = false;							// do not show the close button
                    _showArrows = false;						// do not show the scroll arrow buttons
                    _boldSelected = false;						// do not show selected pages in bold
                    _idePixelArea = true;                       // show a one pixel border at top or bottom
                    IDEPixelBorder = false;                     // do not show a one pixel border round control
                    break;
                case VisualAppearance.MultiDocument:
                    _shrinkPagesToFit = false;					// shrink tabs to fit width
                    _positionAtTop = true;						// draw tabs at bottom of control
                    _showClose = true;							// do not show the close button
                    _showArrows = true;						    // do not show the scroll arrow buttons
                    _boldSelected = true;						// do not show selected pages in bold
                    _idePixelArea = true;                       // show a one pixel border at top or bottom
                    IDEPixelBorder = false;                     // do not show a one pixel border round control
                    break;
            }

            // These properties are the same whichever style is selected
            _hotTrack = false;							// do not hot track paes
            _dimUnselected = true;						// draw dimmed non selected pages

            // Define then starting page for drawing
            if (_tabPages.Count > 0)
                _startPage = 0;
            else
                _startPage = -1;

            _appearance = appearance;

            // Define the correct style indexer
            SetStyleIndex();
        }

        protected virtual void SetStyleIndex()
        {
            switch(_appearance)
            {
                case VisualAppearance.MultiBox:
                    // Always pretend we are plain style
                    _styleIndex = 1;
                    break;
                case VisualAppearance.MultiForm:
                case VisualAppearance.MultiDocument:
                    _styleIndex = (int)_style;
                    break;
            }
        }

        protected virtual bool HideTabsCalculation()
        {
            bool hideTabs = false;
        
            switch(_hideTabsMode)
            {
                case HideTabsModes.ShowAlways:
                    hideTabs = false;
                    break;
                case HideTabsModes.HideAlways:
                    hideTabs = true;
                    break;
                case HideTabsModes.HideUsingLogic:
                    hideTabs = (_tabPages.Count <= 1);                            
                    break;
                case HideTabsModes.HideWithoutMouse:
                    hideTabs = !_mouseOver;
                    break;
            }
            
            return hideTabs;
        }
		
        protected virtual void Recalculate()
        {
            // Reset the need for a recalculation
            _recalculate = false;

            // The height of a tab button is...
            int tabButtonHeight = _position[_styleIndex, (int)PositionIndex.ImageGapTop] + 
                                  _imageGapTopExtra +
                                  _imageHeight + 
                                  _imageGapBottomExtra + 
                                  _position[_styleIndex, (int)PositionIndex.ImageGapBottom] +
                                  _position[_styleIndex, (int)PositionIndex.BorderBottom]; 

            // The height of the tabs area is...
            int tabsAreaHeight = _position[_styleIndex, (int)PositionIndex.BorderTop] + 
                                 tabButtonHeight + _position[_styleIndex, (int)PositionIndex.TabsBottomGap];

			bool hideTabsArea = HideTabsCalculation();

            // Should the tabs area be hidden?
            if (hideTabsArea)
            {
                // ... then do not show the tabs or button controls
                _pageAreaRect = new Rectangle(0, 0, this.Width, this.Height);
                _tabsAreaRect = new Rectangle(0, 0, 0, 0);
            }
            else
            {
                if (_positionAtTop)
                {
                    // Create rectangle that represents the entire tabs area
                    _pageAreaRect = new Rectangle(0, tabsAreaHeight, this.Width, this.Height - tabsAreaHeight);

                    // Create rectangle that represents the entire area for pages
                    _tabsAreaRect = new Rectangle(0, 0, this.Width, tabsAreaHeight);
                }
                else
                {
                    // Create rectangle that represents the entire tabs area
                    _tabsAreaRect = new Rectangle(0, this.Height - tabsAreaHeight, this.Width, tabsAreaHeight);

                    // Create rectangle that represents the entire area for pages
                    _pageAreaRect = new Rectangle(0, 0, this.Width, this.Height - tabsAreaHeight);
                }
            }

            int xEndPos = 0;

            if (!hideTabsArea && _tabPages.Count > 0)
            {
                // The minimum size of a button includes its left and right borders for width,
                // and then fixed height which is based on the size of the image and font
                Rectangle tabPosition;
				
                if (_positionAtTop)
                    tabPosition = new Rectangle(0,		
                                                _tabsAreaRect.Bottom - tabButtonHeight - 
                                                _position[_styleIndex, (int)PositionIndex.BorderTop],
                                                _position[_styleIndex, (int)PositionIndex.BorderLeft] + 
                                                _position[_styleIndex, (int)PositionIndex.BorderRight],
                                                tabButtonHeight);
                else
                    tabPosition = new Rectangle(0,		
                                                _tabsAreaRect.Top + 
                                                _position[_styleIndex, (int)PositionIndex.BorderTop],
                                                _position[_styleIndex, (int)PositionIndex.BorderLeft] + 
                                                _position[_styleIndex, (int)PositionIndex.BorderRight],
                                                tabButtonHeight);

                // Find starting and ending positons for drawing tabs
                int xStartPos = _tabsAreaRect.Left + _tabsAreaStartInset;
                xEndPos = GetMaximumDrawPos();

                // Available width for tabs is size between start and end positions
                int xWidth = xEndPos - xStartPos;

                if (_multiline)
                    RecalculateMultilineTabs(xStartPos, xEndPos, tabPosition, tabButtonHeight);
                else
                    RecalculateSinglelineTabs(xWidth, xStartPos, tabPosition);
            }

            // Position of Controls defaults to the entire page area
            _pageRect = _pageAreaRect;

            // Adjust child controls positions depending on style
            if ((_style == VisualStyle.Plain) && (_appearance != VisualAppearance.MultiBox))
            {
                _pageRect = _pageAreaRect;

                // Shrink by having a border on left,top and right borders
                _pageRect.X += _plainBorderDouble;
                _pageRect.Width -= (_plainBorderDouble * 2) - 1;

                if (!_positionAtTop)
                    _pageRect.Y += _plainBorderDouble;

                _pageRect.Height -= _plainBorderDouble - 1;
				
                // If hiding the tabs then need to adjust the controls positioning
                if (hideTabsArea)
                {
                    _pageRect.Height -= _plainBorderDouble;

                    if (_positionAtTop)
                        _pageRect.Y += _plainBorderDouble;
                }
            }

            // Calcualte positioning of the child controls/forms
            int leftOffset = _ctrlLeftOffset;
            int rightOffset = _ctrlRightOffset;
            int topOffset = _ctrlTopOffset;
            int bottomOffset = _ctrlBottomOffset;

            if (_idePixelBorder && (_style == VisualStyle.IDE))
            {
                leftOffset += 2;
                rightOffset += 2;

                if (_positionAtTop || hideTabsArea)
                    bottomOffset += 2;
                    
                if (!_positionAtTop || hideTabsArea)
                    topOffset += 2;
            }
        
            Point pageLoc = new Point(_pageRect.Left + leftOffset,
                                      _pageRect.Top + topOffset);

            Size pageSize = new Size(_pageRect.Width - leftOffset - rightOffset,
                                     _pageRect.Height - topOffset - bottomOffset);

            // If in Plain style and requested to only show top or bottom border
            if ((_style == VisualStyle.Plain) && _insetBorderPagesOnly)
            {
                // Then need to increase width to occupy where borders would have been 
                pageLoc.X -= _plainBorderDouble;
                pageSize.Width += _plainBorderDouble * 2;

                if (hideTabsArea || _positionAtTop)
                {
                    // Draw into the bottom border area
                    pageSize.Height += _plainBorderDouble;
                }

                if (hideTabsArea || !_positionAtTop)
                {
                    // Draw into the top border area
                    pageLoc.Y -= _plainBorderDouble;
                    pageSize.Height += _plainBorderDouble;
                }
            }

            // Position the host panel appropriately
            _hostPanel.Size = pageSize;
            _hostPanel.Location = pageLoc;
            
            // If we have any tabs at all
            if (_tabPages.Count > 0)
            {
                Rectangle rect = (Rectangle)_tabRects[_tabPages.Count - 1];
				
				// Determine is the right scrolling button should be enabled
                _rightScroll = (rect.Right > xEndPos);
            }
            else
            {
                // No pages means there can be no right scrolling
                _rightScroll = false;
            }

            // Determine if left scrolling is possible
            _leftScroll = (_startPage > 0);

            // Handle then display and positioning of buttons
            RecalculateButtons();
        }

        protected virtual void RecalculateMultilineTabs(int xStartPos, int xEndPos, 
                                                        Rectangle tabPosition, int tabButtonHeight)
        {
            using (Graphics g = this.CreateGraphics())
            {
                // MultiBox style needs a pixel extra drawing room on right
                if (_appearance == VisualAppearance.MultiBox)
                    xEndPos-=2;
                        
                // How many tabs on this line
                int lineCount = 0;
                            
                // Remember which line is

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -