SIL.FieldWorks.FwCoreDlgs.CharContextCtrl.gridContext_CellPainting C# (CSharp) Method

gridContext_CellPainting() private method

Handles the CellPainting event of the gridContext control.
private gridContext_CellPainting ( object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e ) : void
sender object The source of the event.
e System.Windows.Forms.DataGridViewCellPaintingEventArgs The /// instance /// containing the event data.
return void
		private void gridContext_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
		{
			if (colRef.Width == colRef.MinimumWidth)
				colRef.Width = TextRenderer.MeasureText(e.Graphics, "MMM 00:000", gridContext.Font).Width;

			e.AdvancedBorderStyle.All = DataGridViewAdvancedCellBorderStyle.None;
			e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.Single;

			if (e.ColumnIndex == kiColRef)
				e.AdvancedBorderStyle.Right = DataGridViewAdvancedCellBorderStyle.Single;

			e.PaintBackground(e.CellBounds, false);

			TextFormatFlags flags = TextFormatFlags.VerticalCenter |
				TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.NoPrefix;

			if (e.ColumnIndex == colRef.Index)
			{
				Rectangle rc = e.CellBounds;
				int adjForBaseline = (e.RowIndex == 0) ? 2 : 1;
				rc.Height -= adjForBaseline;
				rc.Y += adjForBaseline;
				flags |= TextFormatFlags.Left;
				TextRenderer.DrawText(e.Graphics, e.FormattedValue as string,
					e.CellStyle.Font, rc, gridContext.ForeColor, flags);
			}
			else
			{
				if (gridContext.Columns[e.ColumnIndex].DisplayIndex == 1)
					flags |= TextFormatFlags.Right;
				else if (e.ColumnIndex == colContextItem.Index)
					flags |= TextFormatFlags.HorizontalCenter;

				flags |= TextFormatFlags.NoPadding;
				TextRenderer.DrawText(e.Graphics, e.FormattedValue as string,
					e.CellStyle.Font, e.CellBounds, gridContext.ForeColor, flags);
			}

			e.Handled = true;
		}