예제 #1
0
        private void ColDisplayName_DataCellCustomAreaPaint(object sender, DataGridDataCellPaintEventArgs e)
        {
            //e.PaintBackground()
            if (e.Row == null)
            {
                return;
            }

            //Background
            EhLib.WinForms.BasePaintCellStates cellPaintState = e.CellArgs.State;
            e.CellArgs.State = e.CellArgs.State &
                               ~EhLib.WinForms.BasePaintCellStates.Current &
                               ~EhLib.WinForms.BasePaintCellStates.Focused &
                               ~EhLib.WinForms.BasePaintCellStates.RowSelected;
            Rectangle clientRect = e.CellArgs.ClientRect;

            Rectangle folderAreaRect = e.CellArgs.ClientRect;

            folderAreaRect.X     = e.CellArgs.CustomRect.Left;
            folderAreaRect.Width = e.CellArgs.ClientRect.Left - e.CellArgs.CustomRect.Left;

            e.CellArgs.ClientRect = folderAreaRect;
            e.PaintBackground(e);

            e.CellArgs.ClientRect = clientRect;
            e.CellArgs.State      = cellPaintState;

            //Foreground
            Rectangle areaRect = e.CellArgs.CustomRect;

            areaRect.Width = e.CellArgs.CellRect.Height + 2;
            Image image = (e.Row.SourceItem as ProcessListRow).Icon;

            if (image != null)
            {
                Rectangle folderSignRect = new Rectangle(Point.Empty, image.Size);
                if (folderSignRect.Width > e.CellArgs.CellRect.Height - 2)
                {
                    folderSignRect.Width = e.CellArgs.CellRect.Height - 2;
                }
                if (folderSignRect.Height > e.CellArgs.CellRect.Height - 2)
                {
                    folderSignRect.Height = e.CellArgs.CellRect.Height - 2;
                }
                folderSignRect = EhLib.WinForms.EhLibUtils.RectCenter(folderSignRect, areaRect);
                //folderSignRect.X = folderSignRect.Left + 2;
                e.CellArgs.Graphics.DrawImage(image, folderSignRect);
            }
        }
예제 #2
0
        private void dataGridTextColumn3_DataCellCustomAreaPaint(object sender, DataGridDataCellPaintEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            BasePaintCellStates cellPaintState = e.CellArgs.State;

            e.CellArgs.State = e.CellArgs.State & ~BasePaintCellStates.Current & ~BasePaintCellStates.Focused;
            Rectangle clientRect = e.CellArgs.ClientRect;

            Rectangle folderAreaRect = e.CellArgs.ClientRect;

            folderAreaRect.X     = e.CellArgs.CustomRect.Left;
            folderAreaRect.Width = e.CellArgs.ClientRect.Left - e.CellArgs.CustomRect.Left;

            e.CellArgs.ClientRect = folderAreaRect;
            e.PaintBackground(e);

            e.CellArgs.ClientRect = clientRect;
            e.CellArgs.State      = cellPaintState;

            FileSystemFolterTreeNode node = (FileSystemFolterTreeNode)e.Row.SourceItem;

            {
                Rectangle folderSignRect = folderAreaRect;
                Image     folderImage;
                if (node.Expanded || !node.HasChildren)
                {
                    folderImage = Properties.Resources.FolderOpen;
                }
                else
                {
                    folderImage = Properties.Resources.FolderClosed;
                }
                folderSignRect = new Rectangle(Point.Empty, folderImage.Size);
                folderSignRect = EhLibUtils.RectCenter(folderSignRect, folderAreaRect);
                //folderSignRect.X = folderSignRect.Left + 2;
                e.CellArgs.Graphics.DrawImage(folderImage, folderSignRect);
            }
        }
예제 #3
0
        private void dataGridTextColumn1_DataCellCustomAreaPaint(object sender, DataGridDataCellPaintEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            int        iconPos = 0;
            Rectangle  iconRect;
            SolidBrush backFill = new SolidBrush(e.Column.BackColor);

            int[] iconIndexes = new int[4] {
                -1, -1, -1, -1
            };

            iconRect       = e.CellArgs.CellRect;
            iconRect.Width = 20;

            DataRowView rowView = (DataRowView)e.Row.SourceItem;

            if (rowView["transport1"] is bool && (bool)rowView["transport1"])
            {
                iconIndexes[0] = 0;
            }
            if (rowView["transport2"] is bool && (bool)rowView["transport2"])
            {
                iconIndexes[1] = 1;
            }
            if (rowView["transport3"] is bool && (bool)rowView["transport3"])
            {
                iconIndexes[2] = 2;
            }
            if (rowView["transport4"] is bool && (bool)rowView["transport4"])
            {
                iconIndexes[3] = 3;
            }

            BasePaintCellStates cellPaintState = e.CellArgs.State;

            e.CellArgs.State = e.CellArgs.State & ~BasePaintCellStates.Current & ~BasePaintCellStates.Focused;
            Rectangle clientRect = e.CellArgs.ClientRect;

            foreach (int i in iconIndexes)
            {
                if (i >= 0)
                {
                    e.CellArgs.ClientRect = iconRect;
                    //e.Graphics.FillRectangle(backFill, iconRect);
                    e.PaintBackground(e);
                    if (iconPos == mouseIconIndex && e.CellArgs.RowIndex == dataGrid1.MouseHolderCellCoord.Y)
                    {
                        using (
                            SolidBrush fillBrush = new SolidBrush(Color.FromArgb(255 / 3, SystemColors.Highlight)))
                        {
                            e.CellArgs.Graphics.FillRectangle(fillBrush, iconRect);
                        }
                    }
                    PaintTransportIcon(e.CellArgs.Graphics, iconRect, i);
                    iconPos++;
                    iconRect.Offset(20, 0);
                }
            }

            e.CellArgs.ClientRect = clientRect;
            e.CellArgs.State      = cellPaintState;
        }