Look this code. It's for TStringGrid, but you know DBGrid and StringGrid are derived from TCustomGrid. Sou you can use the code for DBGrid.
procedure DrawSGCell(Sender : TObject; C, R : integer; Rect : TRect;
Style : TFontStyles; Wrap : boolean; Just : TAlignment;
CanEdit : boolean);
{ draws formatted contents in string grid cell at col C, row R;
Style is a set of fsBold, fsItalic, fsUnderline and fsStrikeOut;
Wrap invokes word wrap for the cell's text; Just is taLeftJustify,
taRightJustify or taCenter; if CanEdit false, cell will be given
the background color of fixed cells; call this routine from
grid's DrawCell event }
var
S : string;
DrawRect : TRect;
begin
with (Sender as tStringGrid), Canvas do begin
{ erase earlier contents from default drawing }
if (R >= FixedRows) and (C >= FixedCols) and CanEdit then
Brush.Color:= Color
else
Brush.Color:= FixedColor;
FillRect(Rect);
{ get cell contents }
S:= Cells[C, R];
if length(S) > 0 then begin
case Just of
taLeftJustify : S:= ' ' + S;
taRightJustify : S:= S + ' ';
end;
{ set font style }
Font.Style:= Style;
{ copy of cell rectangle for text sizing }
DrawRect:= Rect;
if Wrap then begin
{ get size of text rectangle in DrawRect, with word wrap }
DrawText(Handle, PChar(S), length(S), DrawRect,
dt_calcrect or dt_wordbreak or dt_center);
if (DrawRect.Bottom - DrawRect.Top) > RowHeights[R] then begin
{ cell word-wraps; increase row height }
RowHeights[R]:= DrawRect.Bottom - DrawRect.Top;
SetGridHeight(Sender as tStringGrid);
end
else begin
{ cell doesn't word-wrap }
DrawRect.Right:= Rect.Right;
FillRect(DrawRect);
case Just of
taLeftJustify : DrawText(Handle, PChar(S), length(S), DrawRect,
dt_wordbreak or dt_left);
taCenter : DrawText(Handle, PChar(S), length(S), DrawRect,
dt_wordbreak or dt_center);
taRightJustify : DrawText(Handle, PChar(S), length(S), DrawRect,
dt_wordbreak or dt_right);
end;
end
end
else
{ no word wrap }
case Just of
taLeftJustify : DrawText(Handle, PChar(S), length(S), DrawRect,
dt_singleline or dt_vcenter or dt_left);
taCenter : DrawText(Handle, PChar(S), length(S), DrawRect,
dt_singleline or dt_vcenter or dt_center);
taRightJustify : DrawText(Handle, PChar(S), length(S), DrawRect,
dt_singleline or dt_vcenter or dt_right);
end;
{ restore no font styles }
Font.Style:= [];
end;
end;
end;
"Code Sample"
<xsl:template match="DBE:Attribute[@name='TestTable']/DBE:Table/DBE:TableRow">
<xsl:variable name="deliveryDate" select="string(DBE:TableData[position()=1])"/>
<tr>
<xsl:apply-templates mode="table" select="DBE:TableData">
<xsl:with-param name="deliveryDate" select="$deliveryDate"/>
</xsl:apply-templates>
</tr>
</xsl:template>
<xsl:template mode="table" match="DBE:TableData">
<xsl:param name="deliveryDate"/>
<td>
<xsl:value-of select="string(.)"/>
</td>
<xsl:if test="count(following-siblings::DBE:TableData)=0">
<td>
<xsl:value-of select="date:add( $deliveryDate, '-P42D')"/>
</td>
</xsl:if>
</xsl:template>
Best Answer
Like so:
Or perhaps you want to set the client area to those dimensions:
Of course, you most commonly set these properties in the Object Inspector at design time and then they are written to your form's .dfm file.
If you want such a change to occur on a button click add a handler for the button click that looks like this:
In this last excerpt you don't need to specify the
MainForm
object instance because the event handler is a member of theTMainForm
class and so theSelf
is implicit.If you wish to follow Ulrich Gerhardt's advice (see comment) and use
SetBounds
then you would write:Finally, if your form has
Scaled = True
then you need to deal with font scaling. Hard coded pixel dimensions like this will not be appropriate for machines with font scaling set to a different value from your machine.