Пример #1
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            Color    backColor, borderColor, foreColor;
            Graphics g = pevent.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            GraphicsPath path = new GraphicsPath();

            if (Radius != 0)
            {
                path.AddArc(0, 0, Radius * 2, Radius * 2, 180, 90);
                path.AddArc(Width - Radius * 2 - 1, 0, Radius * 2, Radius * 2, 270, 90);
                path.AddArc(Width - Radius * 2 - 1, Height - Radius * 2 - 1, Radius * 2, Radius * 2, 0, 90);
                path.AddArc(0, Height - Radius * 2 - 1, Radius * 2, Radius * 2, 90, 90);
            }
            else
            {
                path.AddLines(new Point[] { new Point(1, 0), new Point(Width - 1, 0), new Point(Width - 1, Height - 1), new Point(1, Height - 1) });
            }
            path.CloseFigure();

            if (isHovered && !isPressed && Enabled)
            {
                backColor   = FlatAppearance.MouseOverBackColor == Color.Empty ? defaultOverColor : FlatAppearance.MouseOverBackColor;
                borderColor = FlatAppearance.BorderColor == Color.Empty ? defaultBorderColor : FlatAppearance.BorderColor;
                foreColor   = ForeColor;
            }
            else if (isHovered && isPressed && Enabled)
            {
                backColor   = FlatAppearance.MouseDownBackColor == Color.Empty ? defaultDownColor : FlatAppearance.MouseDownBackColor;
                borderColor = FlatAppearance.BorderColor == Color.Empty ? defaultBorderColor : FlatAppearance.BorderColor;
                foreColor   = ForeColor;
            }
            else if (!Enabled)
            {
                backColor   = BackColor == Color.Transparent ? Parent.BackColor : BackColor;
                borderColor = FlatAppearance.BorderColor == Color.Empty ? defaultBorderColor : FlatAppearance.BorderColor;
                foreColor   = SystemColors.GrayText;
            }
            else
            {
                backColor   = BackColor == Color.Transparent ? Parent.BackColor : BackColor;
                borderColor = FlatAppearance.BorderColor == Color.Empty ? defaultBorderColor : FlatAppearance.BorderColor;
                foreColor   = ForeColor;
            }
            using (SolidBrush brush = new SolidBrush(backColor))
            {
                g.FillPath(brush, path);
            }
            if (FlatAppearance.BorderSize != 0 || isHovered)
            {
                using (Pen pen = new Pen(borderColor, FlatAppearance.BorderSize))
                {
                    g.DrawPath(pen, path);
                }
            }
            TextRenderer.DrawText(g, Text, Font, ClientRectangle, foreColor, backColor, AlignmentTools.ContentAlignment2TextFormatFlags(TextAlign));

            //暂时无用
            if (false && isFocused)
            {
                ControlPaint.DrawFocusRectangle(g, ClientRectangle);
            }
        }
            /// <summary>
            /// Create summary boxes for each Column of the DataGridView  为数据表各列创建统计文本
            /// </summary>
            private void reCreateSumBoxes()
            {
                ReadOnlyTextBox sumBox;

                foreach (Control control in sumBoxHash.Values)
                {
                    this.Controls.Remove(control);
                }
                sumBoxHash.Clear();

                int iCnt = 0;

                List <DataGridViewColumn> sortedColumns = SortedColumns;

                foreach (DataGridViewColumn dgvColumn in sortedColumns)
                {
                    sumBox = new ReadOnlyTextBox();
                    sumBoxHash.Add(dgvColumn, sumBox);

                    sumBox.Top         = 0;
                    sumBox.Height      = dgv.RowTemplate.Height;
                    sumBox.BorderColor = dgv.GridColor;
                    sumBox.ForeColor   = Color.White;

                    if (summaryRowBackColor == null || summaryRowBackColor == Color.Transparent)
                    {
                        sumBox.BackColor = dgv.DefaultCellStyle.BackColor;
                    }
                    else
                    {
                        sumBox.BackColor = summaryRowBackColor;
                    }
                    sumBox.BringToFront();

                    if (dgv.ColumnCount - iCnt == 1)
                    {
                        sumBox.IsLastColumn = true;
                    }

                    if (dgv.SummaryColumns != null && dgv.SummaryColumns.Length > 0)
                    {
                        for (int iCntX = 0; iCntX < dgv.SummaryColumns.Length; iCntX++)
                        {
                            if (dgv.SummaryColumns[iCntX] == dgvColumn.DataPropertyName ||
                                dgv.SummaryColumns[iCntX] == dgvColumn.Name)
                            {
                                dgvColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

                                sumBox.TextAlign = AlignmentTools.TranslateGridColumnAligment(dgvColumn.DefaultCellStyle.Alignment);
                                sumBox.IsSummary = true;

                                sumBox.FormatString = dgvColumn.CellTemplate.Style.Format;
                                if (dgvColumn.ValueType == typeof(System.Int32) || dgvColumn.ValueType == typeof(System.Int16) ||
                                    dgvColumn.ValueType == typeof(System.Int64) || dgvColumn.ValueType == typeof(System.Single) ||
                                    dgvColumn.ValueType == typeof(System.Double) || dgvColumn.ValueType == typeof(System.Single) ||
                                    dgvColumn.ValueType == typeof(System.Decimal))
                                {
                                    sumBox.Tag = System.Activator.CreateInstance(dgvColumn.ValueType);
                                }
                            }
                        }
                    }

                    sumBox.BringToFront();
                    this.Controls.Add(sumBox);

                    iCnt++;
                }

                if (dgv.DisplaySumRowHeader)
                {
                    sumRowHeaderLabel.Visible   = true;
                    sumRowHeaderLabel.Text      = dgv.SumRowHeaderText;
                    sumRowHeaderLabel.ForeColor = dgv.RowHeadersDefaultCellStyle.ForeColor;
                    sumRowHeaderLabel.Font      = new Font(dgv.DefaultCellStyle.Font, dgv.SumRowHeaderTextBold ? FontStyle.Bold : FontStyle.Regular);
                    sumRowHeaderLabel.Height    = dgv.RowTemplate.Height;
                    sumRowHeaderLabel.Width     = dgv.RowHeadersWidth;
                }
                calcSummaries();
                resizeSumBoxes();
            }
Пример #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
            e.Graphics.FillRectangle(new SolidBrush(this.BackColor), e.ClipRectangle);
            for (int i = 0; i < this.TabCount; i++)
            {
                bool      flag1     = (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom) ? true : false;
                bool      flag2     = this.SelectedIndex == i ? true : false;
                Rectangle rectangle = this.GetTabRect(i);
                rectangle.Offset(-2, -2);
                TextFormatFlags format   = AlignmentTools.TabAlignment2Flag(this.Alignment);
                SizeF           textSize = TextRenderer.MeasureText(this.TabPages[i].Text, this.Font, rectangle.Size, format);

                if (this.ImageList != null && (this.TabPages[i].ImageIndex > -1 || !string.IsNullOrEmpty(this.TabPages[i].ImageKey)))
                {
                    if (this.TabPages[i].ImageIndex > -1)
                    {
                        icon = this.ImageList.Images[this.TabPages[i].ImageIndex];
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(this.TabPages[i].ImageKey))
                        {
                            icon = this.ImageList.Images[this.TabPages[i].ImageKey];
                        }
                    }

                    if (!flag2)
                    {
                        e.Graphics.DrawImage(icon,
                                             new Rectangle(this.GetTabRect(i).X + (this.GetTabRect(i).Width - icon.Width) / 2, this.GetTabRect(i).Y + 4, icon.Width, icon.Height),
                                             0, 0, icon.Width, icon.Height, GraphicsUnit.Pixel, ia);
                    }
                    else
                    {
                        e.Graphics.DrawImage(icon, this.GetTabRect(i).X + (this.GetTabRect(i).Width - icon.Width) / 2 - 2, this.GetTabRect(i).Y + 4 - 2);
                    }
                }
                else
                {
                    if (flag2)
                    {
                        if (flag1)
                        {
                            e.Graphics.FillRectangle(Brushes.Lime, Convert.ToInt32((rectangle.Width - textSize.Width) / 2) + rectangle.X, rectangle.Bottom - 2,
                                                     textSize.Width - 4, 2);
                        }
                        else
                        {
                            e.Graphics.FillRectangle(Brushes.Lime, rectangle.Right - 2, Convert.ToInt32((rectangle.Height - textSize.Height) / 2) + rectangle.Y,
                                                     2, textSize.Height + 4);
                        }
                    }
                }

                if (!this.TabPages[i].Text.Equals(string.Empty))
                {
                    TextRenderer.DrawText(e.Graphics, this.TabPages[i].Text, this.Font, rectangle, SystemColors.ControlLightLight, format);
                    rectangle.Offset(-1, 0);
                    TextRenderer.DrawText(e.Graphics, this.TabPages[i].Text, this.Font, rectangle, SystemColors.ControlText, format);
                }
            }
        }
 private void setFormatFlags()
 {
     format.Alignment = AlignmentTools.TranslateAligment(TextAlign);
     format.Trimming  = trimming;
 }