|
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル
"グラデーション文字"
■説明
フォームにグラデーション文字を表示させるサンプルです。
Form1 に Button1 を配置して、Button1 の OnClick イベントを以下
のようにして下さい。
■サンプルコード
//=====================================================================
procedure TForm1.Button1Click(Sender: TObject);
type
TRGB = packed record
case RGB: Boolean of
False :( Color: TColor );
True :( B: Byte; G: Byte; R: Byte; T: Byte );
end;
var
R, G : TRect;
W, H,
i : Integer;
Txt : String;
StartColor, EndColor,
PaintColor : TRGB;
RStep, GStep, BStep : Byte;
begin
Txt := '★ぐらで〜しょん???★';
R := ClientRect;
with Canvas do begin
with Font do begin
Name := 'MS P明朝'; Size := 32;
Style := Style + [fsBold];
end;
W := TextWidth( Txt ); H := TextHeight( Txt );
with R do begin
TopLeft := Point((Right - Left - W ) div 2,
( Bottom - Top - H ) div 2 );
BottomRight := Point( Left + W, Top + H );
end;
StartColor.Color := $00FF0080; //開始色
EndColor.Color := $004080FF; //終了色
PaintColor := StartColor;
RStep := ( EndColor.R - StartColor.R ) div H;
GStep := ( EndColor.G - StartColor.G ) div H;
BStep := ( EndColor.B - StartColor.B ) div H;
SetBkMode( Handle, TRANSPARENT );
BeginPath( Handle );
DrawText( Handle, PChar( Txt ), -1, R,
DT_SINGLELINE or DT_VCENTER or DT_CENTER );
EndPath( Handle );
SelectClipPath( Handle, RGN_AND );
G.TopLeft := R.TopLeft;
G.BottomRight := Point( R.Right, G.Top + 1 );
Brush.Color := PaintColor.Color;
FillRect( G );
for i := R.Top + 1 to R.Bottom do begin
Inc( G.Top );
Inc( G.Bottom );
with PaintColor do begin
R := R + RStep;
G := G + GStep;
B := B + BStep;
Brush.Color := Color;
end;
FillRect( G );
end;
end;
end;
//=====================================================================
98/03/07(土) 18:20 Fermion(KHF03264)
Original document by Fermion 氏 ID:(KHF03264)
ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。
Copyright 1996-2002 Delphi Users' Forum
|