1

私のアプリケーションは、標準の TComboBoxes と TButtonedEdits を使用して、より複雑なドロップダウン パネルを持つコントロールを生成します。2 つのコントロールが同じに見えるようにしたいと思います。特に、プログラムが実行される現在または将来のオペレーティング システムに関係なく、TButtonedEdits のイメージを TComboBoxes のイメージと同一にしたいと考えています (つまり、このイメージはオペレーティング システムによって決定され、Delphi ではないと仮定します)。 )。

実行時に、TComboBox に画像を提供するリソースを TImageList にインストールして、TButtonedEdits で使用できるようにする必要があると思います。そのリソースを見つけて抽出するにはどうすればよいですか?

4

1 に答える 1

2

テーマ エンジンを使用して自分でボタンを描画できます。まず、次のような方法を試してください。

uses
  Themes;

procedure DrawComboBoxButton(ACanvas: TCanvas; ADown, AMouseInControl: Boolean; const ARect: TRect);
var
  ComboElem: TThemedComboBox;
  Details: TThemedElementDetails;
begin
  if ThemeServices.ThemesEnabled then
  begin
    if ADown then
      ComboElem := tcDropDownButtonPressed
    else if AMouseInControl then
      ComboElem := tcDropDownButtonHot
    else
      ComboElem := tcDropDownButtonNormal;
    Details := ThemeServices.GetElementDetails(ComboElem);
    ThemeServices.DrawElement(ACanvas.Handle, Details, ARect);
  end
  else
  begin
    if ADown then
      DrawFrameControl(ACanvas.Handle, ARect, DFC_SCROLL, DFCS_SCROLLCOMBOBOX or DFCS_PUSHED)
    else
      DrawFrameControl(ACanvas.Handle, ARect, DFC_SCROLL, DFCS_SCROLLCOMBOBOX);
  end;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  DrawComboBoxButton(PaintBox1.Canvas, False, False, Bounds(0, 0, 20, 20));
  DrawComboBoxButton(PaintBox1.Canvas, True, False, Bounds(20, 0, 20, 20));
end;

( Embarcadero フォーラムのスレッド「コンボボックスの Windows テーマ」から改作)。

Mike Lischke の「Windows XP Theme Explorer」は、適切な「要素」と「詳細」を見つけるのに役立ちます。そして、この SO スレッドを見てください。

于 2011-01-26T15:37:43.197 に答える