将 TButtonedEdit 图像与 TComboBox 默认图像匹配

发布于 2024-10-14 12:59:11 字数 268 浏览 5 评论 0原文

我的应用程序使用标准 TComboBoxes 和 TButtonedEdits 来生成具有更复杂下拉面板的控件。我希望这两个控件看起来相同。特别是,我希望 TButtonedEdits 上的图像与 TComboBoxes 上的图像相同,无论程序在当前或未来的操作系统上运行(也就是说,假设该图像由操作系统决定,而不是 Delphi )。

我假设我必须在运行时将向 TComboBox 提供图像的资源安装到 TImageList 中,以使其可供我的 TButtonedEdits 使用。如何找到并提取该资源?

My application uses standard TComboBoxes and also TButtonedEdits to produce controls with more complex drop-down panels. I would like the two controls to look the same. In particular, I would like image on my TButtonedEdits to be identical to the image on the TComboBoxes regardless of which current or future operating system the program is run on (that is, assuming that this image is determined by the operating system and not be Delphi).

I assume that I will have to install, at runtime, the resource providing the image to TComboBox into a TImageList to make it available to my TButtonedEdits. How do I locate and extract that resource?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说谎友 2024-10-21 12:59:11

您可以使用主题引擎自己绘制按钮 - 对于初学者来说,尝试这样的操作:(

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;

改编自线程 “组合框中的 Windows 主题”(位于 Embarcadero 论坛)。

Mike Lischke 的“Windows XP 主题资源管理器” 可以帮助您找到正确的“元素”和“细节”。看看这个SO线程

You can use the theme engine to draw the button yourself - try something like this for starters:

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;

(adapted from the thread "Windows themes in combobox" in the Embarcadero forums).

Mike Lischke's "Windows XP Theme Explorer" can help you to find the right "Elements" and "Details". And have a look at this SO thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文