スピード・ボタンへ動的描画するには?

解決


まりも  2006-01-11 19:12:36  No: 19574

下記のようにしてみましたが、反応がありません。
どこが悪いんでしょうか?
イメージ・コンポでは、できるんですが・・。

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;


deldel  2006-01-11 19:39:54  No: 19575

これでできますよ。

  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;


にしの  2006-01-11 19:50:50  No: 19576

幅・高さが設定されていないのと、透明色に左下の色を使用されるためです。
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;


deldel  2006-01-11 19:58:36  No: 19577

参考までに・・・
文字の描画も含めると以下のようにしてます。

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;


まりも  2006-01-11 20:36:27  No: 19578

deldel 様
にしの様

みなさま、素早いレスありがとうございました。
そうかぁ、オブジェクトを作らなくても、直接できるんですね。
いろいろ注意点も書いていただき、予定外のテクニックも
習得できました。
文字のものは、最初反応なくて??となりましたが、ソースよく眺めて
納得しました。ノン・キャプションだったので・・(^^:)。

うひょ〜、とっても嬉しいです。ほんとに助かりました。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加