This is the proc I am using to paint (from DelphiAbout..):
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer;Column: TColumn;
State: TGridDrawState);
var
bitmap : TBitmap;
fixRect : TRect;
bmpWidth : integer;
begin
fixRect := Rect;
if Column.Field = Table1Alarm then
begin
bitmap := TBitmap.Create;
try
ImageList1.GetBitmap(0,bitmap);
bmpWidth := (Rect.Bottom - Rect.Top);
fixRect.Right := Rect.Left + bmpWidth;
//draw the bitmap
DBGrid1.Canvas.StretchDraw(fixRect,bitmap);
finally
bitmap.Free;
end;
fixRect := Rect;
fixRect.Left := fixRect.Left + bmpWidth;
end;
DBGrid1.DefaultDrawColumnCell( fixRect, DataCol, Column,State);
end;
Do this prior to your painting.
You only need to directly paint you bmp afterwards, you don't need
to stretch it, unless you have a desire to do so.
DBGrid1.Canvas.FillRect(Rect);
This will use the current brush assigned to the canvas..
Also, you should be testing the "state" property incase you need to
perform a graying effect or select or unless effect..
Selecting usually involves changing the background colors or some
something different like an underline of check mark, ect..
"Jamie" <jamie_ka1lpa_not_v...@charter.net> ha scritto nel
messaggio news:6s4pn.66268$gF5...@newsfe13.iad...
Alan Lloyd
<alang...@aol.com> ha scritto nel messaggio
news:37a1d1a9-14d3-4815...@30g2000yqi.googlegroups.com...
Please do not top post...
Makes it hard to read the thread.
---
When calculating the width/height from a RECT object, you need to add
1 to each results . Ex. Width := RECT.Right-Rect.Left+1;
The RECT only tells you where the area starts and ends. So if you
were to subtract lets say a horizontal Line RECT, you'd end up with 0
for height. Because the TOp and Bottom would have the same value.
fixRect := Rect; // ( actual values: Top=0, B=17, L=372 R=406)
if Column.Field = Table1Alarm then
begin
bitmap := TBitmap.Create;
try
ImageList1.GetBitmap(0,bitmap);
bmpWidth := (Rect.Bottom - Rect.Top); // Here i get the height of my
cell ( 17-0=17 )
fixRect.Right := Rect.Left + bmpWidth; // and adopt it as teh width
of mybitmap (fixRect.R= 372+17=389)
// now I draw the bitmap (Top=0, B=17, L=372 R=389)
DBGrid1.Canvas.StretchDraw(fixRect,bitmap);
finally
bitmap.Free;
end;
fixRect := Rect; // here I reset
fixRect.Left := fixRect.Left + bmpWidth; // here I add space forn the
bitmap
end;
DBGrid1.DefaultDrawColumnCell( fixRect, DataCol, Column,State);
end;
I tested the routine REMOVING the StretchDraw stetement and found that the
DBGrid column is painted left to right like this: "falFalse" (the field is a
boolean field), i.e. the cell is painted with the bitmap + its value.
Obviously I am making a mistake, but I can't see where I am mistaken !
"Jamie" <jamie_ka1lpa_not_v...@charter.net> ha scritto nel
messaggio news:_Pcpn.35535$NH1...@newsfe14.iad...
why are you calling the defaultDrawColumecell at the end, it just over
writes what you have.
Also, you still don't seem to understand or not reading what I am
telling you. You need to add "1" to the results of a RECT calculations
when determining the size of an element..
Also, I stated to stop, top posting!.
With that, I'll say no more until you reform yourself.!
"Jamie" <jamie_ka1lpa_not_v...@charter.net> ha scritto nel
messaggio news:3zspn.52605$2r7....@newsfe05.iad...
You are supposed to write your responses _below_ the text you are
replying to. Because it is the direction in which people read. From
top to bottom.
Groetjes,
Maarten Wiltink
In other words it writes the data to the cell. But you call it _after_
you have written the bitmap to the cell, thus overwriting the bitmap.
If DefaultDraw is true then the DefaultDrawColumnCell is called before
the OnDrawColumnCell event is called (see OnDrawColumnCell in Help).
Alan Lloyd
Please continue top posting. Have fun getting help.