日期:2014-05-19  浏览次数:20733 次

如何改写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 );
}