Colored DataGrid (winform) code is implemented, the group is open, the code is attached

xiaoxiao2021-03-06  38

Using system.windows.forms; using system.drawing;

Namespace WindowsApplication1 {///

/// DataGridFormat's summary description. /// /// public delegate void formatcellendHandler (Object Sender, DataGridFormatelleventargs Handler);

public class DataGridFormatCellEventArgs: EventArgs {private int _row; private int _col; private Font _font; private Brush _backbrush; private Brush _forebrush; private bool _userBaseClassDrawing; private string _str;

public DataGridFormatCellEventArgs (int row, int col, Font font, Brush backbrush, Brush forebrush) {_row = row; _col = col; _font = font; _backbrush = backbrush; _forebrush = forebrush; _userBaseClassDrawing = false; _str = "";}

Public string getString {get {_str = value;}} public int column}} public int column} set {roundurn _col;}}

Public int rot {get {return _row;} set {_row = value;}}

Public font textFont {get {return _font;} set {_font = value;}}

Public brush backbrush {get {return _BackBrush;} set {_BackBrush = value;}}

Public brush forebrush {get {return _forebrush;} set {_forebrush = value;}}

public bool UserBaseClassDrawing {get {return _userBaseClassDrawing;} set {_userBaseClassDrawing = value;}}} public class DataGridFormatableTextBoxColumn: DataGridTextBoxColumn {public event FormatCellEventHandler SetCellFormat;

Private int _col; public datagram {_col = col;

protected override void Paint (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight) {DataGridFormatCellEventArgs e = new DataGridFormatCellEventArgs (rowNum , this._col, this.dataGridtablestyle.dataGrid.font, backbrush, forebrush; // if (iRow! = rownum) // {// irow = rownum; // strTemp = this.getColumnValueatrow (Source, Irow) .tostring () .Trim (); //} // E.GetString = strTemp; if (setcellformat! = Null) {setcellformat (this, e);} if (E.USERBASECLASSDRAWING) {base.paint (G, Bounds, Source , rowNum, backBrush, foreBrush, alignToRight);} else {g.FillRectangle (e.BackBrush, bounds); g.DrawString (this.GetColumnValueAtRow (source, rowNum) .ToString (), e.TextFont, e.ForeBrush, bounds .X, bounds.y; // MessageBox.show (this.getColumnValueatrow (Source, Rownum) .tostring ());}} (E.TextFont! = This.dataGridTable.DataGrid.font) {E.TextFon t.dispose ();}}

protected override void Edit (System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible) {// comment to make cells unable to become editable base.Edit (source, Rownum, Bounds, Readonly, InstantText, Cellisvisible;

}

转载请注明原文地址:https://www.9cbs.com/read-70668.html

New Post(0)