//#===========================================================================//
//#
//# 类名称 : MyDataGridView
//# 机能概要 : 重写DataGridView
//# 作成者 :
//# 做成日 : 2009/07/01
//# 版本 : 1.0.0.0
//# <变更履历>
//# 版本 日期 变更者 变更内容
//# -------------------------------------------------------------------------
//# 1.0.0.0 2009/07/01 做成
//#
//#
//#===========================================================================//
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace control
{
class MyDataGridView:System.Windows.Forms.DataGridView
{
private System.Windows.Forms.Control controls = null;
public MyDataGridView()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.controls = new System.Windows.Forms.Control();
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
this.SuspendLayout();
//
// controls
//
this.controls.Location = new System.Drawing.Point(0, 0);
this.controls.Name = "controls";
this.controls.Size = new System.Drawing.Size(0, 0);
this.controls.TabIndex = 0;
//
// MyDataGridView
//
this.ColumnHeadersHeight = 25;
this.RowTemplate.Height = 23;
this.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.MyDataGridView_RowPostPaint);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.MyDataGridView_Paint);
((System.ComponentModel.ISupportInitialize)(this)).EndInit();
this.ResumeLayout(false);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (controls != null)
{
controls.Dispose();
}
}
base.Dispose(disposing);
}
private void MyDataGridView_RowPostPaint(object sender, System.Windows.Forms.DataGridViewRowPostPaintEventArgs e)
{
SolidBrush b = new SolidBrush(this.RowHeadersDefaultCellStyle.ForeColor);
e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture)
, this.Font, b, e.RowBounds.Location.X + this.RowHeadersWidth / 2
, e.RowBounds.Location.Y + (e.RowBounds.Height-this.Font.Height) / 2);
}
private void MyDataGridView_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (this.Columns.Count>0 && this.ColumnHeadersVisible == true && this.RowHeadersVisible==true)
{
SolidBrush b = new SolidBrush(this.RowHeadersDefaultCellStyle.ForeColor);
e.Graphics.DrawString("序号", this.Font, b, this.RowHeadersWidth / 2 - this.Font.SizeInPoints
, (this.ColumnHeadersHeight - this.Font.Height) / 2);
}
}
}
}