Клубове Дир.бг
powered by diri.bg
търси в Клубове diri.bg Разширено търсене

Вход
Име
Парола

Клубове
Dir.bg
Взаимопомощ
Горещи теми
Компютри и Интернет
Контакти
Култура и изкуство
Мнения
Наука
Политика, Свят
Спорт
Техника
Градове
Религия и мистика
Фен клубове
Хоби, Развлечения
Общества
Я, архивите са живи
Клубове Дирене Регистрация Кой е тук Въпроси Списък Купувам / Продавам 14:39 19.04.24 
Клубове/ Компютри и Интернет / Delphi Всички теми Следваща тема Пълен преглед*
Информация за клуба
Тема Re: Owner draw в DBGrid [re: Mixy]
Автор Alvian (зелен)
Публикувано10.06.09 14:40  



Mixy, благодаря за идеята !

След извесна заигравка се получи следното:


procedure DrawColumnCellMatchText(const MatchText: String; MatchTextColor, MatchTextBkColor: TColor;
Grid: TDBGrid; const CellRect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Value: string;
TextLeft: Integer;
X: Integer;
Txt: String;
Offset: Integer;
OldBrushColor, OldTextColor: TColor;
B: TRect;

procedure DrawTextBitmap(const txt: String; const BrushColor, TextColor: TColor);
begin
DrawBitmap.Canvas.Brush.Color := BrushColor;
DrawBitmap.Canvas.Font.Color := TextColor;
DrawBitmap.Canvas.TextOut(TextLeft + X, 2, Txt);
Inc(X, DrawBitmap.Canvas.TextWidth(Txt));
end;

begin
OldBrushColor := Grid.Canvas.Brush.Color;
OldTextColor := Grid.Canvas.Font.Color;

Value := '';
if Assigned(Column.Field) then
Value := Column.Field.DisplayText;

DrawBitmap.Canvas.Lock;
try
DrawBitmap.Canvas.Brush.Assign(Grid.Canvas.Brush);
DrawBitmap.Canvas.Font.Color := Grid.Canvas.Font.Color;

X := 0;
DrawBitmap.Width := Max(DrawBitmap.Width, CellRect.Right - CellRect.Left);
DrawBitmap.Height := Max(DrawBitmap.Height, CellRect.Bottom - CellRect.Top);
B := Rect(0, 0, CellRect.Right - CellRect.Left, CellRect.Bottom - CellRect.Top);
DrawBitmap.Canvas.FillRect(B);

// TODO: BiDi mode
case Column.Alignment of
taLeftJustify:
TextLeft := 2;
taRightJustify:
TextLeft := (CellRect.Right - CellRect.Left) - DrawBitmap.Canvas.TextWidth(Value) - 3;
else { taCenter }
TextLeft := ((CellRect.Right - CellRect.Left) shr 1) - (DrawBitmap.Canvas.TextWidth(Value) shr 1);
end;

Offset := Pos(MatchText, Value);
while Offset > 0 do begin
Txt := Copy(Value, 1, Offset - 1);
if Txt <> '' then begin
Delete(Value, 1, Length(Txt));
DrawTextBitmap(Txt, OldBrushColor, OldTextColor);
end;

Txt := Copy(Value, 1, Length(MatchText));
Delete(Value, 1, Length(Txt));
DrawTextBitmap(Txt, MatchTextBkColor, MatchTextColor);

Offset := Pos(MatchText, Value);
end;
if Value <> '' then
DrawTextBitmap(Value, OldBrushColor, OldTextColor);

Grid.Canvas.Brush.Style := bsClear;
Grid.Canvas.CopyRect(CellRect, DrawBitmap.Canvas, B);
finally
DrawBitmap.Canvas.Unlock;
end;
end;


За мен работи перфектно.
DrawBitmap какво е може да видите в DBGrids.pas. Просто си го копирах по подходящ начин в моя unit.



Цялата тема
ТемаАвторПубликувано
* Owner draw в DBGrid Alvian   09.06.09 16:52
. * Re: Owner draw в DBGrid Mixy   09.06.09 17:55
. * Re: Owner draw в DBGrid Alvian   10.06.09 14:40
Клуб :  


Clubs.dir.bg е форум за дискусии. Dir.bg не носи отговорност за съдържанието и достоверността на публикуваните в дискусиите материали.

Никаква част от съдържанието на тази страница не може да бъде репродуцирана, записвана или предавана под каквато и да е форма или по какъвто и да е повод без писменото съгласие на Dir.bg
За Забележки, коментари и предложения ползвайте формата за Обратна връзка | Мобилна версия | Потребителско споразумение
© 2006-2024 Dir.bg Всички права запазени.