Mark Williams 14 Posted December 31, 2024 I create a themed form on the fly. The form caption varies each time. I am trying to set the form width to a sufficient size so that the caption is displayed in full. I can't see any easy way of doing this. I'm guessing I have to analyse all the elements on the title bar and go from there. Starting with the text extent of the desired caption: var Canvas: TCanvas; s: string; r: TRect; t: TTextFormat; begin s := caption; Canvas := TCanvas.Create; try Canvas.Handle := GetDC(0); TStyleManager.ActiveStyle.GetTextExtent(Canvas.Handle, teTextLabel, s, t, r); finally ReleaseDC(0, Canvas.Handle); end; First, I cannot work out which themed element represents the title bar caption. It has to be within the range [teCategoryButtons..teTextLabel]] ie: teCategoryButtons, teCategoryPanelGroup, teCheckListBox, teControlBar, teDataNavButtons, teGrid, teHint, tePanel, teTabSet, teTextLabel, I've opted for teTextLabel, but have no idea if this is right. Secondly, the code does not compile. "No overloaded version of GetTextExtent...". I don't understand why. GetTextExtent is declared as: function GetTextExtent(DC: HDC; Details: TThemedElementDetails; const Text: string; Flags: TTextFormat; out ExtentRect: TRect): Boolean; overload; Assuming I can get this to work and correctly calculate the required text width for the title bar, I guess I then have to work out the width required for all other elements on the title bar and set form width accordingly. It will probably take me the rest of my limited remaining years to work out how to query all the other elements on the title bar. Can anyone suggest a simpler way of achieving this? Share this post Link to post
Pat Foley 52 Posted December 31, 2024 1. put a "banner" on the form say a tpanel and get the textextent of its caption there. use to set bounds of form add in 20*button count and be done. 2. Look at TMessageForm in Vcl.dialogs source that shows how team Emba does it. Time ~ 3 hours. 3. Pix shows windows dialog vs a TmessageForm. (arrows point out differences in needing different code to view classtype of dialogs when not using style this is 12.2 though.) Share this post Link to post
Mark Williams 14 Posted December 31, 2024 1. But that will give me the textextent of the caption as it appears on a tpanel, not as it appears on the title bar. I assume these can be different depending on the theme. 2. Can't see how TMessageForm helps. Don't see that it addresses the theming issue. Share this post Link to post
Remy Lebeau 1445 Posted December 31, 2024 (edited) 12 hours ago, Mark Williams said: Secondly, the code does not compile. "No overloaded version of GetTextExtent...". I don't understand why. Because teTextLabel is a TThemedElement enum value but GetTextExtent() wants a TThemedElementDetails record instead. Edited December 31, 2024 by Remy Lebeau 1 Share this post Link to post
Pat Foley 52 Posted December 31, 2024 2 hours ago, Mark Williams said: 2. Can't see how TMessageForm helps. Don't see that it addresses the theming issue. 2. May need to review how the opendialog uses style in the source then. I am running 12.2 but next year will test some stuff with 10.2 win 7 and will compare the source 3. Pix shows showmessage with and without style. Share this post Link to post