我想更改與 Delphi 的 FMX TBindNavigator 關聯的默認影像。當我在 IDE 中右鍵單擊 TBindNavigator 控制元件時,我看不到以下選項:
- 編輯自定義樣式...
- 編輯默認樣式...
如何更改與 TBindNavigator 關聯的影像?
例如,我想讓 FMX BindNavigator 看起來像 VCL DBNavigator
由此:

對此:

uj5u.com熱心網友回復:
在 Delphi FMX 中,TBindNavigator 組件似乎不可定制,因為它不公開任何樣式屬性,但可以對組件的源代碼 ( Fmx.Bind.Navigator.pas) 進行一些更改以覆寫其默認樣式。請注意,這些更改僅在運行時可見,并且在 Delphi 11 上的空白專案上進行了測驗。
TBindNavigator 中的按鈕默認使用相同的 TCornerButton 樣式,但您可以更改此設定,使其使用 TButton 的默認樣式或其他自定義樣式。找到
TBindNavButton.GetDefaultStyleLookupName函式并更改Result 的值:Result := 'ButtonStyle';按鈕中的顏色都是相同的,因為組件使用 TCornerButton(或 TButton,如果如上修改)的文本顏色。要指定不同的顏色為每個按鈕找到TBindNavButton.ApplyStyle程式和替換的內容里面的
if FPath <> nil then支票是這樣的:case FIndex of nbFirst: FPath.Fill.Color := TAlphaColors.Blue; nbPrior: FPath.Fill.Color := TAlphaColors.Blue; nbNext: FPath.Fill.Color := TAlphaColors.Blue; nbLast: FPath.Fill.Color := TAlphaColors.Blue; nbInsert: FPath.Fill.Color := TAlphaColors.Firebrick; nbDelete: FPath.Fill.Color := TAlphaColors.Firebrick; nbEdit: FPath.Fill.Color := TAlphaColors.Blue; nbPost: FPath.Fill.Color := TAlphaColors.Forestgreen; nbCancel: FPath.Fill.Color := TAlphaColors.Firebrick; nbRefresh: FPath.Fill.Color := TAlphaColors.Blue; nbApplyUpdates: FPath.Fill.Color := TAlphaColors.Blue; nbCancelUpdates: FPath.Fill.Color := TAlphaColors.Blue; end;代替使用影像 FMX TBindNavigator 使用矢量路徑來呈現其圖示,這些可以在與 SVG 格式的字串相同的源檔案中找到。要更改圖示,您必須擁有其 SVG 資料并在 BtnTypePath 陣列中替換其對應的字串。例如,這里的編輯圖示看起來像一張紙,被向上箭頭代替,看起來更像 VCL 對應物:
BtnTypePath: array[TBindNavigateBtn] of string = ( ... // edit 'M 291.667,346.113 L 316.667,311.738 L 341.236,346.113 Z ', // Arrow pointing up ... );圖示的大小也在檔案中進行了硬編碼。要更改此設定,請找到該
TCustomBindNavigator.InitButtons程序并編輯這些行:Btn.FPath.Width := 12; // Make them smaller Btn.FPath.Height := 12; // Make them smaller
通過之前的所有更改,我們現在有了一個在運行時更類似于 VCL 對應物的欄。

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/408511.html
標籤:
