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

📄 windowdetailcaption.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 4 页
字号:

                // Force the ImageAttribute for the button to be set
                SetButtonState();
            }
        }

        protected override void UpdateAutoHideImage()
        {
            if (_pinnedImage)
                _hideButton.ImageIndexEnabled = (int)ImageIndex.AutoShow;
            else
                _hideButton.ImageIndexEnabled = (int)ImageIndex.AutoHide;
        }

        protected override void UpdateMaximizeImage()
        {
            if ((_maxButton != null) && (_maxInterface != null))
            {
                bool enabled = _maxInterface.IsMaximizeAvailable();

                if (!enabled)
                {
                    if (_maxButton.Visible)
                        _maxButton.Hide();
                }
                else
                {
                    bool maximized = _maxInterface.IsWindowMaximized(this.ParentWindow);

                    if (!_maxButton.Visible)
                        _maxButton.Show();

                    if (maximized)
                        _maxButton.ImageIndexEnabled = (int)ImageIndex.EnabledVerticalMin;	
                    else
                        _maxButton.ImageIndexEnabled = (int)ImageIndex.EnabledVerticalMax;	
                }
            }
        }

        protected void SetButtonState()
        {
            if (this.ParentWindow != null)
            {
                if (this.ParentWindow.ContainsFocus)
                {
                    if (_closeButton.BackColor != _manager.ActiveColor)
                    {
                        _closeButton.BackColor = _manager.ActiveColor;
                        _closeButton.ImageAttributes = _activeAttr;
                        _closeButton.Invalidate();
                    }

                    if (_hideButton != null)
                    {
                        if (_hideButton.BackColor != _manager.ActiveColor)
                        {
                            _hideButton.BackColor = _manager.ActiveColor;
                            _hideButton.ImageAttributes = _activeAttr;
                            _hideButton.Invalidate();
                        }
                    }

                    if (_maxButton != null)
                    {
                        if (_maxButton.BackColor != _manager.ActiveColor)
                        {
                            _maxButton.BackColor = _manager.ActiveColor;
                            _maxButton.ImageAttributes = _activeAttr;
                            _maxButton.Invalidate();
                        }
                    }
                }
                else
                {
                    if (_closeButton.BackColor != this.BackColor)
                    {
                        _closeButton.BackColor = this.BackColor;
                        _closeButton.ImageAttributes = _inactiveAttr;
                        _closeButton.Invalidate();
                    }

                    if (_hideButton != null)
                    {
                        if (_hideButton.BackColor != this.BackColor)
                        {
                            _hideButton.BackColor = this.BackColor;
                            _hideButton.ImageAttributes = _inactiveAttr;
                            _hideButton.Invalidate();
                        }
                    }

                    if (_maxButton != null)
                    {
                        if (_maxButton.BackColor != this.BackColor)
                        {
                            _maxButton.BackColor = this.BackColor;
                            _maxButton.ImageAttributes = _inactiveAttr;
                            _maxButton.Invalidate();
                        }
                    }
                }
            }
        }

        protected override void RecalculateButtons()
        {
            int buttonX = this.Width - _buttonWidth - _buttonSpacer;
            int buttonY = (_fixedLength - _yInset * 2 - _buttonHeight) / 2 + _yInset;
        
            if (_showCloseButton)
            {
                // Button position is fixed, regardless of our size
                _closeButton.Location = new Point(buttonX, buttonY);

                _closeButton.Size = new Size(_buttonWidth, _buttonHeight);
    		
                // Give the button a very thin button
                _closeButton.BorderWidth = 1;

                // Let the location of the control be updated for us
                _closeButton.Anchor = AnchorStyles.Right;

                // Just in case currently hidden
                _closeButton.Show();
                
                // Define start of next button
                buttonX -= _buttonWidth;
            }
            else
                _closeButton.Hide();
                        
            if (_showHideButton && !_ignoreHideButton)
            {
                // Button position is fixed, regardless of our size
                _hideButton.Location = new Point(buttonX, buttonY);

                _hideButton.Size = new Size(_buttonWidth, _buttonHeight);
			
                // Give the button a very thin button
                _hideButton.BorderWidth = 1;

                // Let the location of the control be updated for us
                _hideButton.Anchor = AnchorStyles.Right;

                // Just in case currently hidden
                _hideButton.Show();

                // Define start of next button
                buttonX -= _buttonWidth;
                
                UpdateAutoHideImage();
            }
            else
                _hideButton.Hide();
            
            if (_maxButton != null)
            {
                // Button position is fixed, regardless of our size
                _maxButton.Location = new Point(buttonX, buttonY);

                _maxButton.Size = new Size(_buttonWidth, _buttonHeight);
			
                // Give the button a very thin button
                _maxButton.BorderWidth = 1;

                // Let the location of the control be updated for us
                _maxButton.Anchor = AnchorStyles.Right;

                // Define start of next button
                buttonX -= _buttonWidth;

                UpdateMaximizeImage();
            }
        }

        protected override void CreateButtons()
        {
            // Define the ImageList and which ImageIndex to show initially
            _closeButton = new InertButton(_images, (int)ImageIndex.Close);
            _hideButton = new InertButton(_images, (int)ImageIndex.AutoHide);
			
            _closeButton.Size = new Size(_buttonWidth, _buttonHeight);
            _hideButton.Size = new Size(_buttonWidth, _buttonHeight);

            // Let the location of the control be updated for us
            _closeButton.Anchor = AnchorStyles.Right;
            _hideButton.Anchor = AnchorStyles.Right;

            // Define the button position relative to the size set in the constructor
            _closeButton.Location = new Point(_fixedLength - _buttonWidth - _buttonSpacer, 
                                              (_fixedLength - _yInset * 2 - _buttonHeight) / 2 + _yInset);
            
            _hideButton.Location = new Point(_fixedLength - (_buttonWidth - _buttonSpacer) * 2, 
                                             (_fixedLength - _yInset * 2 - _buttonHeight) / 2 + _yInset);

            // Give the button a very thin button
            _closeButton.BorderWidth = 1;
            _hideButton.BorderWidth = 1;

            // Define correct color setup
            _closeButton.BackColor = this.BackColor;
            _closeButton.ImageAttributes = _inactiveAttr;
            _hideButton.BackColor = this.BackColor;
            _hideButton.ImageAttributes = _inactiveAttr;

            // Add to the display
            Controls.Add(_closeButton);
            Controls.Add(_hideButton);

            // Let base class perform common actions
            base.CreateButtons();
        }

		protected void UpdateCaptionHeight(Font captionFont)
		{
            // Dynamically calculate the required height of the caption area
            _fixedLength = (int)captionFont.GetHeight() + (_yInset + _yInsetExtra) * 2;
    
            int minHeight = _buttonHeight + _yInset * 4 + 1;

            // Maintain a minimum height to allow correct showing of buttons
            if (_fixedLength < minHeight)
                _fixedLength = minHeight;

			this.Size = new Size(_fixedLength, _fixedLength);
			
			RecalculateButtons();

			Invalidate();
		}

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            // Overriden to prevent background being painted
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            bool focused = false;

            if (this.ParentWindow != null)
                focused = this.ParentWindow.ContainsFocus;

            // Sometimes the min/max button is created and then an attempt is made to 
            // hide the button. But for some reason it does not always manage to hide 
            // the button. So forced to check here everytime to ensure its hidden.
            UpdateMaximizeImage();

            SetButtonState();
            
            Size ourSize = this.ClientSize;

            int xEnd = ourSize.Width;
            int yEnd = ourSize.Height - _yInset * 2;

            Rectangle rectCaption = new Rectangle(0, _yInset, xEnd, yEnd - _yInset + 1);

            using(SolidBrush backBrush = new SolidBrush(this.BackColor),
                             activeBrush = new SolidBrush(_manager.ActiveColor),
                             activeTextBrush = new SolidBrush(_manager.ActiveTextColor),
                             inactiveBrush = new SolidBrush(_manager.InactiveTextColor))
            {
                // Is this control Active?
                if (focused)
                {
                    // Fill the entire background area
                    e.Graphics.FillRectangle(backBrush, e.ClipRectangle);
    	
                    // Use a solid filled background for text
                    e.Graphics.FillRectangle(activeBrush, rectCaption);
    			
                    // Start drawing text a little from the left
                    rectCaption.X += _buttonSpacer;
                    rectCaption.Y += 1;
                    rectCaption.Height -= 2;

                    // Reduce the width to account for close button
                    rectCaption.Width -= _closeButton.Width + _buttonSpacer;

                    // Reduce width to account for the optional maximize button
                    if ((_maxButton != null) && (_maxButton.Visible))
                        rectCaption.Width -= _closeButton.Width;
    				
                    e.Graphics.DrawString(this.Text, _manager.CaptionFont, activeTextBrush, rectCaption);
                }
                else
                {
                    // Fill the entire background area
                    e.Graphics.FillRectangle(backBrush, e.ClipRectangle);
    	            
                    // Inactive and so use a rounded rectangle
                    using (Pen dark = new Pen(ControlPaint.LightLight(_manager.InactiveTextColor)))
                    {
                        e.Graphics.DrawLine(dark, 1, _yInset, xEnd - 2, _yInset);
                        e.Graphics.DrawLine(dark, 1, yEnd, xEnd - 2, yEnd);
                        e.Graphics.DrawLine(dark, 0, _yInset + 1, 0, yEnd - 1);
                        e.Graphics.DrawLine(dark, xEnd - 1, _yInset + 1, xEnd - 1, yEnd - 1);

                        // Start drawing text a little from the left
                        rectCaption.X += _buttonSpacer;
                        rectCaption.Y += 1;
                        rectCaption.Height -= 2;

                        // Reduce the width to account for close button
                        rectCaption.Width -= _closeButton.Width + _buttonSpacer;

                        // Reduce width to account for the optional maximize button
                        if ((_maxButton != null) && (_maxButton.Visible))
                            rectCaption.Width -= _maxButton.Width;

                        e.Graphics.DrawString(this.Text, _manager.CaptionFont, inactiveBrush, rectCaption);
                    }
                }	
            }
            
            // Let delegates fire through base
            base.OnPaint(e);

            // Always get the button to repaint as we have painted over their area
            _closeButton.Refresh();
        }				
    }
}

⌨️ 快捷键说明

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