System.Windows.Forms.DataGridViewTextBoxCell.Paint C# (CSharp) Method

Paint() protected method

protected Paint ( Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts ) : void
graphics System.Drawing.Graphics
clipBounds System.Drawing.Rectangle
cellBounds System.Drawing.Rectangle
rowIndex int
cellState DataGridViewElementStates
value object
formattedValue object
errorText string
cellStyle System.Windows.Forms.DataGridViewCellStyle
advancedBorderStyle System.Windows.Forms.DataGridViewAdvancedBorderStyle
paintParts DataGridViewPaintParts
return void
		protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
		{
			// Prepaint
			DataGridViewPaintParts pre = DataGridViewPaintParts.Background | DataGridViewPaintParts.SelectionBackground;
			pre = pre & paintParts;
			
			base.Paint (graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, pre);

			// Paint content
			if (!IsInEditMode && (paintParts & DataGridViewPaintParts.ContentForeground) == DataGridViewPaintParts.ContentForeground) {
				Color color = Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;

				TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.TextBoxControl;
				flags |= AlignmentToFlags (cellStyle.Alignment);

				Rectangle contentbounds = cellBounds;
				
				contentbounds.Height -= 2;
				contentbounds.Width -= 2;
				
				// If we are top aligned, give ourselves some padding from the top
				if (((int)cellStyle.Alignment & 7) > 0) {
					contentbounds.Offset (0, 2);
					contentbounds.Height -= 2;
				}

				if (formattedValue != null)
					TextRenderer.DrawText (graphics, formattedValue.ToString (), cellStyle.Font, contentbounds, color, flags);
			}

			// Postpaint
			DataGridViewPaintParts post = DataGridViewPaintParts.Border | DataGridViewPaintParts.Focus | DataGridViewPaintParts.ErrorIcon;
			post = post & paintParts;

			base.Paint (graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, post);
		}