Beispiel #1
0
		private Rectangle DrawCellContents(Graphics g, CellInfo cell, StyleInfo style, Rectangle r)
		{
			using (Brush foreBrush = new LinearGradientBrush(r.Location, new Point(r.X, r.Bottom), 
				style.ForeColor, style.ForeColor2))
			{
				if (cell.Image != null)
				{
					Rectangle r2 = new Rectangle(r.X + 1, r.Y + 1, cell.Image.Width, cell.Image.Height);
					if (r2.Height > r.Height)
					{
						r2.Height = r.Height;
					}
					else if (r2.Height < r.Height)
					{
						r2.Y += ((r.Height - r2.Height) >> 1);
					}
					g.DrawImage(cell.Image, r2);
					r.X += cell.Image.Width + 2;
					r.Width -= (cell.Image.Width + 2);
				}
				r.X += 1;
				r.Y += 1;
				r.Width -= 1;
				r.Height -= 1;
				StringFormat sf = new StringFormat();
				sf.Alignment = HorAlToStrAl(style.Algnment);
				sf.LineAlignment = StringAlignment.Center;
				sf.Trimming = StringTrimming.EllipsisCharacter;
				sf.FormatFlags = StringFormatFlags.NoWrap;
				g.DrawString(cell.Text, Font, foreBrush, r, sf);
			}
			return r;
		}
Beispiel #2
0
		protected virtual StyleInfo DoGenerateDefaultStyle(int column, DataGridViewCellStyle cellStyle, DataGridViewElementStates cellState)
		{
			StyleInfo style = null;
			if ((cellState & DataGridViewElementStates.Selected) != DataGridViewElementStates.Selected)
			{
				style = new StyleInfo(cellStyle.BackColor, cellStyle.ForeColor,
					cellStyle.Font, Columns[column].Alignment,
					ChangeColor(cellStyle.BackColor, -32), 
					ChangeColor(cellStyle.ForeColor, 32));
			}
			else
			{
				if (realGrid.Focused && Enabled)
				{
					style = new StyleInfo(SystemColors.ActiveCaption,
						SystemColors.ActiveCaptionText,
						cellStyle.Font, Columns[column].Alignment,
						SystemColors.GradientActiveCaption,
						SystemColors.ActiveCaptionText);
				}
				else
				{
					style = new StyleInfo(SystemColors.InactiveCaption, SystemColors.InactiveCaptionText,
						cellStyle.Font, Columns[column].Alignment,
					   SystemColors.GradientInactiveCaption,
					   SystemColors.InactiveCaptionText);
				}
			}
			return style;
		}
Beispiel #3
0
		private void realGrid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
		{
			Rectangle r = e.CellBounds;
			Graphics g = e.Graphics;
			int row = e.RowIndex;
			int column = e.ColumnIndex;
			DataGridViewCellStyle cellStyle = e.CellStyle;
			DataGridViewElementStates cellState = e.State;
			if (row >= 0 && column >= 0)
			{
				CellInfo cell = DoGetCellInfo(row, column);
				StyleInfo style = DoGetStyleInfo(row, column);
				if (style == null)
				{
					style = DoGenerateDefaultStyle(column, cellStyle, cellState);
				}
				int ident = DoGetIdent(row, column);
				r = DoDrawBackground(r, g, style);
				r.X += 2;
				r.Y += 1;
				r.Width -= 4;
				r.Height -= 2;
				if (DoDrawExpansion(column))
				{
					Rectangle r3 = new Rectangle(r.X + ident, r.Y, expansionImageWidth, r.Height);
					ident += expansionImageWidth;
					bool? isExpanded = DoGetExpanded(row, column);
					if (isExpanded != null)
					{
						if ((Application.VisualStyleState & VisualStyleState.ClientAreaEnabled) ==
							VisualStyleState.ClientAreaEnabled && VisualStyleRenderer.IsSupported)
						{
							VisualStyleRenderer rdr = new VisualStyleRenderer(
								(((bool)isExpanded) ?
								VisualStyleElement.TreeView.Glyph.Opened :
								VisualStyleElement.TreeView.Glyph.Closed));
							rdr.DrawBackground(g, r3);
						}
						else
						{
							Image img = (((bool)isExpanded) ? Resources.Collapse : Resources.Expand);
							if (img.Height < r3.Height)
							{
								int chg = r3.Height - img.Height;
								r3.Y += chg / 2;
								r3.Height = img.Height;
							}
							g.DrawImage(img, r3);
						}
					}
				}
				r.X += ident;
				r.Width -= ident;
				DrawCellContents(g, cell, style, r);
				e.Handled = true;
			}
			else if (row == -1 && column >= 0)
			{
				CellInfo cell = new CellInfo(Columns[column].HeadingText,
					Columns[column].Image);
				StyleInfo style = new StyleInfo(Color.Transparent, e.CellStyle.ForeColor,
					e.CellStyle.Font, Columns[column].HeadingAlignment);
				e.PaintBackground(e.ClipBounds, false);
				r.X += 2;
				r.Y += 1;
				r.Width -= 4;
				r.Height -= 2;
				DrawCellContents(g, cell, style, r);
				e.Handled = true;
			}
		}
Beispiel #4
0
		protected virtual Rectangle DoDrawBackground(Rectangle r, Graphics g, StyleInfo style)
		{
			using (Brush bgBrush = new LinearGradientBrush(r.Location, new Point(r.X, r.Bottom),
				style.BackColor, style.BackColor2))
				g.FillRectangle(bgBrush, r);
			Rectangle r2 = new Rectangle(r.Location, r.Size - new Size(1, 1));
			using (Pen edgePen = new Pen(GridColor))
			{
				g.DrawLine(edgePen, new Point(r2.Left, r2.Bottom), new Point(r2.Right, r2.Bottom));
				g.DrawLine(edgePen, new Point(r2.Right, r2.Top), new Point(r2.Right, r2.Bottom));
			}
			return r;
		}
        private void realGrid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            Rectangle                 r         = e.CellBounds;
            Graphics                  g         = e.Graphics;
            int                       row       = e.RowIndex;
            int                       column    = e.ColumnIndex;
            DataGridViewCellStyle     cellStyle = e.CellStyle;
            DataGridViewElementStates cellState = e.State;

            if (row >= 0 && column >= 0)
            {
                CellInfo  cell  = DoGetCellInfo(row, column);
                StyleInfo style = DoGetStyleInfo(row, column);
                if (style == null)
                {
                    style = DoGenerateDefaultStyle(column, cellStyle, cellState);
                }
                int ident = DoGetIdent(row, column);
                r         = DoDrawBackground(r, g, style);
                r.X      += 2;
                r.Y      += 1;
                r.Width  -= 4;
                r.Height -= 2;
                if (DoDrawExpansion(column))
                {
                    Rectangle r3 = new Rectangle(r.X + ident, r.Y, expansionImageWidth, r.Height);
                    ident += expansionImageWidth;
                    bool?isExpanded = DoGetExpanded(row, column);
                    if (isExpanded != null)
                    {
                        if ((Application.VisualStyleState & VisualStyleState.ClientAreaEnabled) ==
                            VisualStyleState.ClientAreaEnabled && VisualStyleRenderer.IsSupported)
                        {
                            VisualStyleRenderer rdr = new VisualStyleRenderer(
                                (((bool)isExpanded) ?
                                 VisualStyleElement.TreeView.Glyph.Opened :
                                 VisualStyleElement.TreeView.Glyph.Closed));
                            rdr.DrawBackground(g, r3);
                        }
                        else
                        {
                            Image img = (((bool)isExpanded) ? Resources.Collapse : Resources.Expand);
                            if (img.Height < r3.Height)
                            {
                                int chg = r3.Height - img.Height;
                                r3.Y     += chg / 2;
                                r3.Height = img.Height;
                            }
                            g.DrawImage(img, r3);
                        }
                    }
                }
                r.X     += ident;
                r.Width -= ident;
                DrawCellContents(g, cell, style, r);
                e.Handled = true;
            }
            else if (row == -1 && column >= 0)
            {
                CellInfo cell = new CellInfo(Columns[column].HeadingText,
                                             Columns[column].Image);
                StyleInfo style = new StyleInfo(Color.Transparent, e.CellStyle.ForeColor,
                                                e.CellStyle.Font, Columns[column].HeadingAlignment);
                e.PaintBackground(e.ClipBounds, false);
                r.X      += 2;
                r.Y      += 1;
                r.Width  -= 4;
                r.Height -= 2;
                DrawCellContents(g, cell, style, r);
                e.Handled = true;
            }
        }