2013-05-09 16 views
1

我想繪製TSeStyleFont像位圖樣式設計器中的vcl樣式背景。 有沒有什麼方法可以繪製背景?來自TSeStyleFont的繪畫背景

enter image description here

我必須做一個嘗試: - 使用DrawElement第一繪製對象中的位圖。 - 比目前的位圖複製到使用「Bitmap.Canvas.CopyRect」一諾特爾乾淨位圖的問題是:這梅索德不會有銘文,如複選框對象正常工作......

var 
    bmp, bmp2: TBitmap; 
    Details: TThemedElementDetails; 
    R, Rn: TRect; 
begin 
    bmp := TBitmap.Create; 
    bmp2 := TBitmap.Create; 
    R := Rect(0, 0, 120, 20); 
    Rn := Rect(0 + 4, 0 + 4, 120 - 4, 20 - 4); 
    bmp.SetSize(120, 20); 
    bmp2.SetSize(120, 20); 
    Details := StyleServices.GetElementDetails(TThemedButton.tbPushButtonHot); 
    StyleServices.DrawElement(bmp.Canvas.Handle, Details, R); 
    bmp2.Canvas.CopyRect(R, bmp.Canvas, Rn); 
    Canvas.Draw(10, 10, bmp2); 
    bmp.Free; 
    bmp2.Free; 

end; 
+0

待辦事項你想繪製屁股的背景上? – RRUZ 2013-05-09 20:46:17

+1

這個問題充其量是令人困惑的,請更改問題 – Peter 2013-05-09 21:02:34

+0

>你想繪製按鈕的背景嗎? 是的,就像這樣。實際上我已經嘗試過了: - 使用DrawElement首先在位圖中繪製對象。 - 使用'Bitmap.Canvas.CopyRect' 將當前位圖複製到另一個乾淨的位圖問題是:此方法無法正確使用具有字形的對象,如CheckBox ... – 2013-05-09 21:09:25

回答

5

如果您想要繪製按鈕的背景,您必須使用StyleServices.DrawElement方法通過正確的TThemedButton部件。

如果你想畫無死角的背景試試這個樣本

uses 
    Vcl.Styles, 
    Vcl.Themes; 

{$R *.dfm} 

procedure TForm2.Button1Click(Sender: TObject); 
var 
    Details : TThemedElementDetails; 
begin 
    Details := StyleServices.GetElementDetails(tbPushButtonPressed); 
    StyleServices.DrawElement(PaintBox1.Canvas.Handle, Details, PaintBox1.ClientRect); 

    Details := StyleServices.GetElementDetails(tbPushButtonNormal); 
    StyleServices.DrawElement(PaintBox2.Canvas.Handle, Details, PaintBox2.ClientRect); 
end; 

enter image description here

,你可以調整TRect的範圍,像這樣

Details : TThemedElementDetails; 
    LRect : TRect; 
begin 
    LRect:=PaintBox1.ClientRect; 
    LRect.Inflate(3,3); 

    Details := StyleServices.GetElementDetails(tbPushButtonPressed); 
    StyleServices.DrawElement(PaintBox1.Canvas.Handle, Details, LRect); 

    LRect:=PaintBox2.ClientRect; 
    LRect.Inflate(3,3); 
    Details := StyleServices.GetElementDetails(tbPushButtonNormal); 
    StyleServices.DrawElement(PaintBox2.Canvas.Handle, Details, LRect); 
end; 

enter image description here

+0

我想要這樣的內容:[ 1]:http://i.stack.imgur.com/bUnzJ.png: – 2013-05-09 21:24:02

+0

和答案樣本有什麼不同? – RRUZ 2013-05-09 21:27:06

+0

背景是一個完整的矩形(沒有角落) – 2013-05-09 21:29:08