VirtualStringTree標題具有「背景」屬性,但將其設置爲不同的顏色不會更改顏色。我懷疑樹是使用Windows主題渲染的。如何設置VirtualStringTree標題的顏色?
如何設置顏色?
VirtualStringTree標題具有「背景」屬性,但將其設置爲不同的顏色不會更改顏色。我懷疑樹是使用Windows主題渲染的。如何設置VirtualStringTree標題的顏色?
如何設置顏色?
您可以使用屬性THeader.Background
,但您必須從TreeOptions.PaintOptions
排除toThemeAware
。這會關閉主題,正如TLama在他上面的評論中所說的那樣。
我建議你使用的事件OnAdvancedHeaderDraw
和OnHeaderDrawQueryElements
。必須包含在Header.Options
中才能生效。 (至少)[hpeBackground]
和OnAdvancedHeaderDraw
您自定義繪圖。
參見該示例(source):
procedure TfrmMain.MyVSTHeaderDrawQueryElements(Sender: TVTHeader;
var PaintInfo: THeaderPaintInfo; var Elements: THeaderPaintElements);
begin
Elements := [hpeBackground];
end;
procedure TfrmMain.MyVSTAdvancedHeaderDraw(Sender: TVTHeader;
var PaintInfo: THeaderPaintInfo; const Elements: THeaderPaintElements);
begin
if hpeBackground in Elements then
begin
PaintInfo.TargetCanvas.Brush.Color := clFuchsia; // <-- your color here
if Assigned(PaintInfo.Column) then
DrawFrameControl(PaintInfo.TargetCanvas.Handle, PaintInfo.PaintRectangle, DFC_BUTTON, DFCS_FLAT or DFCS_ADJUSTRECT); // <-- I think, that this keeps the style of the header background, but I'm not sure about that
PaintInfo.TargetCanvas.FillRect(PaintInfo.PaintRectangle);
end;
end;
如果未將Assigned(PaintInfo.Column)then語句添加到查詢元素事件中,則最好添加。 'hpeBackground'元素也用於繪圖板。在繪圖事件中只需填充矩形。 – TLama
@TLama你的意思是「盤子」是什麼意思? –
很好的回答!代碼是最終的時候我會接受它。 –
procedure TfrmDepositDefrayalSingly.vstItemsManuallyHeaderDrawQueryElements(Sender: TVTHeader;
var PaintInfo: THeaderPaintInfo; var Elements: THeaderPaintElements);
begin
Elements := [hpeBackground];
end;
procedure TfrmDepositDefrayalSingly.vstItemsManuallyAdvancedHeaderDraw(Sender: TVTHeader;
var PaintInfo: THeaderPaintInfo; const Elements: THeaderPaintElements);
begin
if hpeBackground in Elements then
begin
PaintInfo.TargetCanvas.Brush.Color := cGlobalVar.BasicColor;
PaintInfo.TargetCanvas.FillRect(PaintInfo.PaintRectangle);
if Assigned(PaintInfo.Column) then
begin
PaintInfo.TargetCanvas.Brush.Color := clGray;
PaintInfo.TargetCanvas.FrameRect(PaintInfo.PaintRectangle);
end;
end;
end;
該屬性被用於報頭的背景下,對於不板。而且您必須關閉控件的主題(從'TreeOptions.PaintOptions'中排除'toThemeAware')。你所要求的聽起來更像是自定義繪圖的任務。你想要畫什麼(一個圖像會是理想的)? – TLama
關閉ThemeAware不是一種選擇,因爲它不再平坦。我只需要一個較暗的灰色作爲標題背景色... –
[喜歡這個](http://i.imgur.com/xevOLcX.png)?請注意,背景在該圖片上沒有漸變。該漸變需要一些額外的工作。 – TLama