2011-01-26 80 views
1

我的应用程序使用标准TComboBoxes和TButtonedEdits来生成具有更复杂下拉面板的控件。我希望两个控件看起来一样。特别是,我希望TButtonedEdits上的图像与TComboBox上的图像完全相同,无论该程序运行在哪个当前或将来的操作系统上(即假设此图像由操作系统决定而不是Delphi )。将TButtonedEdit图像与TComboBox匹配默认图像

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

回答

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; 

(在英巴卡迪诺论坛改编自线程"Windows themes in combobox")。

Mike Lischke的"Windows XP Theme Explorer"可以帮助您找到正确的“Elements”和“Details”。并看看this SO thread

+0

我没有谷歌tcDropDownButtonNormal,并找到一些代码示例。不幸的是,我没有对主题引擎的知识或理解,并试图谷歌_that_只让我参考旧的第三方引擎。你有什么建议可以在某个地方阅读吗? – 2011-01-28 03:50:07