下記のようにしてみましたが、反応がありません。
どこが悪いんでしょうか?
イメージ・コンポでは、できるんですが・・。
var
Bitmap : TBitMap;
procedure TForm1.Button1Click(Sender: TObject);
begin
Bitmap := TBitmap.Create;
with Bitmap do begin
Canvas.brush.color := clRed;
Canvas.brush.style := bsSolid;
Canvas.FillRect(Rect(0,0,15,35));
end;
SpeedButton1.Glyph := Bitmap;
end;
これでできますよ。
SpeedButton1.Glyph.Height := SpeedButton1.Height;
SpeedButton1.Glyph.Width := SpeedButton1.Width;
with SpeedButton1.Glyph do begin
Canvas.brush.color := clRed;
Canvas.brush.style := bsSolid;
Canvas.FillRect(Rect(0,0,15,35));
end;
幅・高さが設定されていないのと、透明色に左下の色を使用されるためです。
var
Bitmap : TBitMap;
procedure TForm1.Button1Click(Sender: TObject);
begin
Bitmap := TBitmap.Create;
with Bitmap do begin
width:=15;//追加:幅を設定
height:=35;//追加:高さを設定
Canvas.brush.color := clRed;
Canvas.brush.style := bsSolid;
Canvas.FillRect(Rect(0,0,15,35));
Canvas.Pixels[0 ,Height-1]:=0;//追加:左下に黒を設定
end;
SpeedButton1.Glyph := Bitmap;
end;
参考までに・・・
文字の描画も含めると以下のようにしてます。
var
saCap: AnsiString;
begin
saCap := SpeedButton1.Caption;
SpeedButton1.Caption := '';
SpeedButton1.Glyph.Height := SpeedButton1.Height;
SpeedButton1.Glyph.Width := SpeedButton1.Width;
with SpeedButton1.Glyph do begin
Canvas.brush.color := clRed;
Canvas.brush.style := bsSolid;
Canvas.FillRect(Rect(0, 0, Width-3, Height-3));
Canvas.Brush.Style := bsClear;
Canvas.Font := SpeedButton1.Font;
Canvas.TextOut((Width - Canvas.TextWidth(saCap)) div 2,
(Height - Canvas.TextHeight(saCap)) div 2,
saCap);
end;
end;
deldel 様
にしの様
みなさま、素早いレスありがとうございました。
そうかぁ、オブジェクトを作らなくても、直接できるんですね。
いろいろ注意点も書いていただき、予定外のテクニックも
習得できました。
文字のものは、最初反応なくて??となりましたが、ソースよく眺めて
納得しました。ノン・キャプションだったので・・(^^:)。
うひょ〜、とっても嬉しいです。ほんとに助かりました。
ツイート | ![]() |