Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 27 Apr 2024, 13:02

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: 17 Oct 2012, 05:34 
Offline

Joined: 15 Oct 2012, 07:05
Posts: 17
Hi,
How can i change color of a part of StringField content in DBGridEh.
for example:
my field is: Qolam2010
Thanks.


Top
 Profile  
 
PostPosted: 17 Oct 2012, 15:09 
Offline

Joined: 09 Feb 2012, 17:05
Posts: 124
Hi,

How do you store the color and start position to change color ?

Rico


Top
 Profile  
 
PostPosted: 17 Oct 2012, 17:48 
Offline

Joined: 15 Oct 2012, 07:05
Posts: 17
my issue is tow case:
1- show formatted text such as Rtf
2- change color of part of Field's Value in DrawColumnCell :
for example: Field.value:='this is a book' i want:
in DrawColumnCell change color of 'book' -> this is a book.

thanks.


Top
 Profile  
 
PostPosted: 17 Oct 2012, 19:52 
Offline

Joined: 15 Oct 2012, 07:05
Posts: 17
a Simple Solution:
i assume Field's value is 'book,pencil' .
for colorize first word: book,pencil
Code:
procedure TfrmViewQList.DBGridEh1AdvDrawDataCell(Sender: TCustomDBGridEh; Cell,
  AreaCell: TGridCoord; Column: TColumnEh; const ARect: TRect;
  var Params: TColCellParamsEh; var Processed: Boolean);
var
  DrawTextRect: TRect;
  S,s1: String;
  H: Integer;
  BrushStyle: TBrushStyle;
  clr: TColorRef;
begin
if Column.FieldName='rnames' then begin

  Sender.DefaultDrawColumnDataCell(Cell, AreaCell, Column, ARect, Params);
  Processed := True;
  Sender.Canvas.Font := Sender.FieldColumns['rnames'].Font;
  if gdFocused in Params.State then
    Sender.Canvas.Font.Color := clHighlightText;
  DrawTextRect := ARect;
  S := Sender.FieldColumns['rnames'].DisplayText;
  s1:=copy(s,1,pos(',',s)-1);
  H := Sender.Canvas.TextHeight(S);
  if DrawTextRect.Top + H < DrawTextRect.Bottom  then
  begin
    BrushStyle := Sender.Canvas.Brush.Style;
    Sender.Canvas.Brush.Style := BrushStyle;
    clr:=Sender.Canvas.Font.Color;
    Sender.Canvas.Font.Color:=clRed;
    Sender.Canvas.TextRect(DrawTextRect, DrawTextRect.Left, DrawTextRect.Top, s1);
    Sender.Canvas.Font.Color:=clR;
    Inc(DrawTextRect.Left, sender.Canvas.TextWidth(s1));
    Sender.Canvas.TextRect(DrawTextRect, DrawTextRect.Left,
     DrawTextRect.Top, Copy(S,Length(s1)+1,Length(s)-Length(s1)));
    Sender.Canvas.Brush.Style := BrushStyle;
  end;
end;
end;


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group