读书人

怎么改写Event?想把控件的Event改写为

发布时间: 2012-01-16 23:36:51 作者: rapoo

如何改写Event?想把控件的Event改写为Public Method,该如何来做呢?
如下:
===================================================================
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
grid.RowHeadersWidth,
e.RowBounds.Height);

TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1 + "/ " + grid.Rows.Count).ToString(),
grid.RowHeadersDefaultCellStyle.Font,
rectangle,
grid.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
}

===============================================================

因为所有的DataGridView都会用到这个事件,我想把它做成Public,关键是参数e用什么来传进去呢?



[解决办法]
public void RowPostPaint( object sender, DataGridViewRowPostPaintEventArgs e )
{
DataGridView grid = ( DataGridView )sender ;

Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
grid.RowHeadersWidth,
e.RowBounds.Height);

TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1 + "/ " + grid.Rows.Count).ToString(),
grid.RowHeadersDefaultCellStyle.Font,
rectangle,
grid.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
}


private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
RowPostPaint( sender , e );
}

读书人网 >C#

热点推荐