Delphi中DBGrid行列颜色设置.docVIP

  • 13
  • 0
  • 约1.21万字
  • 约 14页
  • 2016-09-10 发布于天津
  • 举报
Delphi中DBGrid行列颜色设置.doc

Delphi中DBGrid行列颜色设置1. ? 纵向斑马线效果:实现网格的奇数列和偶数列分别以不同的颜色显示,以区别相邻的数据列。 ? ? ? file://在DbGrid的DrawColumnCell事件中编写如下代码: ? ? ? Case ? DataCol ? Mod ? 2 ? = ? 0 ? of ? ? ? True: ? DbGrid1.Canvas.Brush.Color:= ? clBlue; ? file://偶数列用蓝色 ? ? ? False: ? DbGrid1.Canvas.Brush.Color:= ? clAqua; ? file://奇数列用浅绿色 ? ? ? End; ? ? ? DbGrid1.Canvas.Pen.Mode:=pmMask; ? ? ? DbGrid1.DefaultDrawColumnCell ? (Rect, ? DataCol, ? Column, ? State); ? ? ?? ? 2. ? 纵向斑马线,同时以红色突出显示当前单元格效果:以突出显示当前选中的字段。 ? ? ?   file://将上述代码修改为: ? ? ?  Case ? DataCol ? Mod ? 2 ? = ? 0 ? of ? ? ?  True: ? DbGrid1.Canvas.Brush.Color:= ? clBlue; ? file://偶数列用蓝色 ? ? ?  False: ? DbGrid1.Canvas.Brush.Color:= ? clAqua; ? file://奇数列用浅绿色 ? ? ? End; ? ? ? If ? ((State ? = ? [gdSelected]) ? or ? (State=[gdSelected,gdFocused])) ? then ? ? ? ?   If ? Not ? DbGrid1.SelectedRows.CurrentRowSelected ? then ? ? ?DbGrid1.Canvas.Brush.Color:=clRed; ? file://当前选中单元格显示红色 ?       DbGrid1.Canvas.Pen.Mode:=pmMask; ? ? ?  DbGrid1.DefaultDrawColumnCell ? (Rect, ? DataCol, ? Column, ? State); ? ? ? ? 上述两种方法突出了列的显示效果。 ? ? ? ?   3.在数据网格中以红色突出显示当前选中的行。 ? ? ?  设置DbGrid控件的Options属性中的dgRowSelect属性为真,Color属性为clAqua(背景色), ? 在DbGrid的DrawColumnCell事件中编写如下代码: ? ? ? if ? ((State ? = ? [gdSelected]) ? or ? (State=[gdSelected,gdFocused])) ? then ? ? ? DbGrid1.Canvas.Brush.color:=clRed; ? file://当前行以红色显示,其它行使用背景的浅绿色 ? ? ? DbGrid1.Canvas.pen.mode:=pmmask; ? ? ? DbGrid1.DefaultDrawColumnCell ? (Rect, ? DataCol, ? Column, ? State); ? ? ? 4.行突显的斑马线效果:既突出当前行,又区分不同的列(字段)。 ? ? ? file://其它属性设置同3,将上述代码修改为: ? ? ? if ? ((State ? = ? [gdSelected]) ? or ? (State=[gdSelected,gdFocused])) ? then ? ? ? begin ? ? ? Case ? DataCol ? Mod ? 2 ? = ? 0 ? of ? ? ? True ? : ? DbGrid1.Canvas.Brush.color:=clRed; ? file://当前选中行的偶数列显示红色 ? ? ? False: ? DbGrid1.Canvas.Brush.color:=clblue; ? file://当前选中行的奇数列显示蓝色 ? ? ? end; ? ? ? DbGrid1.Canvas.pen.mode:=pmmask; ? ? ? DbGrid1.DefaultDrawColumnCell ? (Rect, ? DataCol, ? Column, ? State); ? ? ? end; ? ?

文档评论(0)

1亿VIP精品文档

相关文档