C1 FlexGrid for WinForms的自动检索实现

时间:2024-11-14 03:48:40

1、首先设置DrawMode属性为OwnerDraw,就可以触发OwnerDraw事件。//To enable control to fire OwnerDrawCell Eventc1FlexGrid1.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw;

2、每次,text文字改变的时候,就会触发OwerDraw事件重画grid的每个单元格。包含搜索文字的单元格将会画成不同的颜色,和默认的不同。void c1FlexGrid1_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e){//Check if OwnerDrawCell used for Searchingif (_StartSearch){//Getting content of cell stringCellContent = e.Text;//Check whether cell contains the Text in TextBoxif (CellContent.Contains(tbSearchBox.Text)){SolidBrush brush = new SolidBrush(Color.Red);Single x = 0;//Traverse celltext and set ForeColor.for (int i = 0; i < CellContent.Length; i++){string character = CellContent[i].ToString();//Color the Text of Search Result with Rede.Graphics.DrawString(character, c1FlexGrid1.Font, brush, e.Bounds.X + x, e.Bounds.Y);//Next character needs to be shifted right;//depending on the space occupied by the previous character as per its FontSize/FontStylex += (e.Graphics.MeasureString(character, this.c1FlexGrid1.Font)).Width - 3;//To restrict FlexGrid to draw default cell contente.Handled = true;}}}//Whether Search completed throughout all cells of gridif (e.Row == c1FlexGrid1.Rows.Count && e.Col == c1FlexGrid1.Cols.Count) { _StartSearch = false; }}

3、本文所实现的效果如图所示:

C1 FlexGrid for WinForms的自动检索实现
© 2025 手抄报圈
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com