Andwho.Windows.Forms.ToolBar.OnPaint C# (CSharp) Метод

OnPaint() защищенный Метод

引发 System.Windows.Forms.Form.Paint 事件。
protected OnPaint ( PaintEventArgs e ) : void
e PaintEventArgs 包含事件数据的 System.Windows.Forms.PaintEventArgs。
Результат void
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            int xPos = this.Padding.Left;
            int yPos = this.Padding.Top;
            foreach (ToolItem item in this.Items)
            {
                // 当前 Item 所在的矩型区域
                Rectangle itemRect = new Rectangle(xPos, yPos, this._itemSize.Width, this._itemSize.Height);
                if (!DesignMode)
                {
                    item.Rectangle = itemRect;
                    if (item != this.SelectedItem)
                    {
                        if (item.MouseState == EMouseState.Normal ||
                            item.MouseState == EMouseState.Leave)
                        {
                            g.DrawImage(this._normalImage, itemRect);
                        }
                        else if (item.MouseState == EMouseState.Move ||
                            item.MouseState == EMouseState.Up)
                        {
                            g.DrawImage(this._hoverImage, itemRect);
                        }
                    }
                    else
                    {
                        g.DrawImage(this._pushedImage, itemRect);
                    }
                }
                if (item.Image != null)     // 绘制图片
                {
                    Rectangle imageRect = new Rectangle();
                    imageRect.X = itemRect.X + (itemRect.Width - this._imageSize.Width) / 2;
                    imageRect.Y = 6;
                    imageRect.Size = this._imageSize;
                    g.DrawImage(item.Image, imageRect);
                }
                if (!string.IsNullOrEmpty(item.Text))   // 绘制文字
                {
                    Rectangle textRect = new Rectangle();
                    textRect.X = itemRect.X;
                    textRect.Y = itemRect.Height / 5 * 3;
                    textRect.Height = itemRect.Height / 5 * 2;
                    textRect.Width = itemRect.Width;
                    TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter;
                    TextRenderer.DrawText(g, item.Text, this.Font, textRect, this.ForeColor, flags);
                }
                xPos += itemRect.Width + this._itemSpace;
            }
        }