Ejemplo n.º 1
0
        /// <summary>
        /// 自定义表头颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bandedGridView1_CustomDrawBandHeader(object sender, DevExpress.XtraGrid.Views.BandedGrid.BandHeaderCustomDrawEventArgs e)
        {
            //背景颜色没有设置且为空,则默认
            if (e.Band.AppearanceHeader == null || (e.Band.AppearanceHeader.BackColor == Color.Empty && !e.Band.AppearanceHeader.Options.UseBackColor))
            {
                return;
            }
            Rectangle rect = e.Bounds;

            rect.Inflate(-1, -1);
            // 填充标题颜色.
            e.Graphics.FillRectangle(new SolidBrush(e.Band.AppearanceHeader.BackColor), rect);
            e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
            // 绘制过滤和排序按钮.
            foreach (DrawElementInfo info in e.Info.InnerElements)
            {
                if (!info.Visible)
                {
                    continue;
                }
                ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
            }
            e.Handled = true;
        }
Ejemplo n.º 2
0
        private void gvwBase_CustomDrawBandHeader(object sender, DevExpress.XtraGrid.Views.BandedGrid.BandHeaderCustomDrawEventArgs e)
        {
            try
            {
                //return;
                Rectangle rect = e.Bounds;
                rect.Inflate(new Size(1, 1));

                Brush brush = new SolidBrush(e.Appearance.BackColor);
                e.Graphics.FillRectangle(brush, rect);
                Pen  pen_horizental = new Pen(Color.Blue, 3F);
                Pen  pen_vertical   = new Pen(Color.Blue, 4F);
                Pen  line           = new Pen(Color.White, 3F);
                bool boBorder       = false;
                if (e.Band == null)
                {
                    return;
                }
                string[] ls = e.Band.Caption.Split('\n');

                if (e.Band.HasChildren)
                {
                    if (e.Band.Children[0].Columns.Count > 0)
                    {
                        if (e.Band.Children[0].Columns[0].Caption == strCol)
                        {
                            boBorder = true;
                        }
                    }
                }
                else
                {
                    if (e.Band.Columns.Count > 0)
                    {
                        if (e.Band.Columns[0].Caption == strCol)
                        {
                            boBorder = true;
                        }
                    }
                }

                if (boBorder)
                {
                    if (e.Band.HasChildren)
                    {
                        e.Graphics.DrawLine(pen_horizental, rect.X, rect.Y, rect.X + rect.Width, rect.Y);
                    }
                    else
                    {
                        //e.Graphics.DrawLine(line, rect.X, rect.Y, rect.X + rect.Width, rect.Y);
                    }
                    // draw right
                    e.Graphics.DrawLine(pen_vertical, rect.X + rect.Width - 2, rect.Y, rect.X + rect.Width - 2, rect.Y + rect.Height);


                    // draw left
                    e.Graphics.DrawLine(pen_horizental, rect.X + 1, rect.Y, rect.X + 1, rect.Y + rect.Height);


                    e.Graphics.DrawString(ls[0], e.Appearance.GetFont(), new SolidBrush(e.Appearance.GetForeColor()), rect, e.Appearance.GetStringFormat());
                    e.Handled = true;
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void advBandedGridViewPublication_CustomDrawBandHeader(object sender, DevExpress.XtraGrid.Views.BandedGrid.BandHeaderCustomDrawEventArgs e)
        {
            if (e.Band == null)
            {
                return;
            }
            if (e.Band == gridBandDiscounts || e.Band == gridBandColorPricing)
            {
                Rectangle rect = e.Bounds;
                ControlPaint.DrawBorder3D(e.Graphics, e.Bounds);
                Brush brush =
                    e.Cache.GetGradientBrush(rect, e.Band.AppearanceHeader.BackColor,
                                             e.Band.AppearanceHeader.BackColor2, e.Band.AppearanceHeader.GradientMode);
                rect.Inflate(-1, -1);
                e.Graphics.FillRectangle(brush, rect);
                e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
                e.Painter.DrawObject(e.Info);

                Image img = null;
                if (e.Band == gridBandDiscounts)
                {
                    img = imageList.Images[0];
                }
                else if (e.Band == gridBandColorPricing)
                {
                    img = this.Publication.ColorOption == BusinessClasses.ColorOptions.BlackWhite ? null : imageList.Images[1];
                }
                if (img != null)
                {
                    Point p = Point.Empty;
                    p.X = (e.Bounds.Width - (img.Width + (int)e.Graphics.MeasureString(e.Info.Caption, advBandedGridViewPublication.Appearance.BandPanel.Font).Width + 15)) / 2 + e.Bounds.Left;
                    p.Y = (e.Bounds.Height - img.Height) / 2 + e.Bounds.Top;
                    e.Graphics.DrawImage(img, p);
                }

                e.Handled = true;
            }
        }