Пример #1
0
        private void SfDataGrid_DrawCell(object sender, DrawCellEventArgs e)
        {
            if (this.sfDataGrid.CurrentCell != null && this.sfDataGrid.CurrentCell.IsEditing)
            {
                return;
            }

            if (e.Column.MappingName == "Total" && e.DataRow.RowType == RowType.DefaultRow)
            {
                var          value    = (e.DataRow.RowData as SalesByYear).Total;
                var          graphics = e.Graphics;
                var          rect     = e.Bounds;
                Rectangle    rect1    = new Rectangle(rect.X + 15, rect.Y + 6, rect.Width / 6, rect.Height / 2);
                StringFormat format   = new StringFormat();
                if (value > 2500000)
                {
                    ShapesPainter.DrawTriangle(graphics, rect1, TriangleDirection.Up, Brushes.Green, new Pen(Color.Green), true);
                    graphics.DrawString(e.DisplayText, e.Style.Font.GetFont(), new SolidBrush(e.Style.TextColor), rect.X + 40, rect.Y + 5, format);
                }
                else
                {
                    ShapesPainter.DrawTriangle(graphics, rect1, TriangleDirection.Down, Brushes.Red, new Pen(Color.Red), true);
                    graphics.DrawString(e.DisplayText, e.Style.Font.GetFont(), new SolidBrush(e.Style.TextColor), rect.X + 40, rect.Y + 5, format);
                }

                Pen borderPen = new Pen(Brushes.LightGray);
                graphics.DrawLine(borderPen, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom);
                graphics.DrawLine(borderPen, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
                e.Handled = true;
            }
        }
Пример #2
0
        /// <summary>
        /// Used to customize the cell
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SfDataGrid_DrawCell(object sender, DrawCellEventArgs e)
        {
            if (this.sfDataGrid.CurrentCell != null && this.sfDataGrid.CurrentCell.IsEditing)
            {
                return;
            }

            if (e.Column.MappingName == "Change" && e.DataRow.RowType == RowType.DefaultRow)
            {
                var          graphics = e.Graphics;
                var          rect     = e.Bounds;
                Rectangle    rect1    = new Rectangle(rect.X + 20, rect.Y + 6, rect.Width / 6, rect.Height / 2);
                StringFormat format   = new StringFormat();

                e.Style.HorizontalAlignment = HorizontalAlignment.Center;
                var drawingObj = new DrawingHelper();
                var value      = drawingObj.GetType().GetMethod("ConvertToStringAlignment", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, Type.DefaultBinder, new Type[] { typeof(HorizontalAlignment) }, new ParameterModifier[] { }).Invoke(drawingObj, new object[] { e.Style.HorizontalAlignment });
                format.Alignment = (StringAlignment)value;

                var value1 = drawingObj.GetType().GetMethod("ConvertToStringAlignment", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, Type.DefaultBinder, new Type[] { typeof(VerticalAlignment) }, new ParameterModifier[] { }).Invoke(drawingObj, new object[] { e.Style.VerticalAlignment });
                format.LineAlignment = (StringAlignment)value1;

                if ((e.DataRow.RowData as StockData).Change > 0)
                {
                    ShapesPainter.DrawTriangle(graphics, rect1, TriangleDirection.Up, Brushes.Green, new Pen(Color.Green), true);
                    graphics.DrawString(e.DisplayText, e.Style.Font.GetFont(), new SolidBrush(Color.Green), rect.X + 92, rect.Y + 13, format);
                }
                else
                {
                    ShapesPainter.DrawTriangle(graphics, rect1, TriangleDirection.Down, Brushes.Red, new Pen(Color.Red), true);
                    graphics.DrawString(e.DisplayText, e.Style.Font.GetFont(), new SolidBrush(Color.Red), rect.X + 90, rect.Y + 13, format);
                }
                Pen borderPen = new Pen(Brushes.LightGray);
                graphics.DrawLine(borderPen, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom);
                graphics.DrawLine(borderPen, rect.Left, rect.Bottom - 1, rect.Right, rect.Bottom - 1);
                e.Handled = true;
            }
        }