Beispiel #1
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 #2
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;
		}
        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;
            }
        }