- This topic has 7 replies, 2 voices, and was last updated 6 years ago by
Support.
-
AuthorPosts
-
March 23, 2019 at 8:51 pm #38207
TAZ
ParticipantFor TsComboBox, you can use CB_SETDROPPEDWIDTH to change the combobox dropdown width.
CB_SETDROPPEDWIDTH has no effect on TsComboBoxEx. Is there anything you can use to adjust the TsComboBoxEx dropdown width?
Thanks.
March 26, 2019 at 5:51 am #59293Support
KeymasterWhich version of the Delphi do you uses?
I have tried the CB_SETDROPPEDWIDTH message with TsComboBoxEx component, it works well in my test.
March 26, 2019 at 9:50 am #59298TAZ
ParticipantDelphi version is Tokyo 10.2.3
I have attached a project that demonstrates the problem. This is based on https://www.thoughtc…n-width-1058301
Simple and Auto for regular sComboBox works. Does not work for sComboBoxEx.
I also included the last example in the article. It does not work for either.
So, how are you able to get it to work for sComboBoxEx?
Thanks.
'Support' wrote:Which version of the Delphi do you uses?
I have tried the CB_SETDROPPEDWIDTH message with TsComboBoxEx component, it works well in my test.
March 27, 2019 at 6:24 am #59302Support
KeymasterThank you for the demo.
Positions of controls are correct there?
Look what I see on my side.
March 27, 2019 at 8:52 am #59303TAZ
ParticipantWell, I feel silly. I will get back to you.
'Support' wrote:Thank you for the demo.
Positions of controls are correct there?
Look what I see on my side.
March 27, 2019 at 2:00 pm #59306TAZ
ParticipantI figured it out and I am not sure why I had to do this. The original problem was that setting the dropdown width was fine when the font size was 8. However, I have the font size set to 12. The dropdown width did not adjust. That was puzzling.
In my research I came across using a TBitmap to set the text length. It worked.
I am not sure why I had to assign the combo box font to the bitmap and then use the bitmap textwidth to get the proper dropdown width. Very odd.
https://stackoverflo…-without-canvas
See attached.
Thanks.
'TAZ' wrote:Well, I feel silly. I will get back to you.
March 27, 2019 at 2:40 pm #59307TAZ
ParticipantOne more change to the procedure if the item width is greater than the combo box width. Have to account for the possible vertical scrollbar which was in the wrong place.
I also include changes in the dropdown width if images are included. Interesting adventure.
Code:procedure ComboBoxEx_AutoWidth(const theComboBox: TsComboBoxEx);
const
HORIZONTAL_PADDING = 4;
var
itemsFullWidth, idx, itemWidth: integer;
c: TBitmap;
begin
c := TBitmap.Create;
try
itemsFullWidth := 0;
c.Canvas.Font.Assign(theComboBox.Font);
for idx := 0 to Pred(theComboBox.Items.Count) do
begin
itemWidth := c.Canvas.TextWidth(theComboBox.Items[idx]);
Inc(itemWidth, (2 * HORIZONTAL_PADDING));
if (itemWidth > itemsFullWidth) then
itemsFullWidth := itemWidth;
end;
if (theComboBox.DropDownCount < theComboBox.Items.Count) then
itemsFullWidth := (itemsFullWidth + GetSystemMetrics(SM_CXVSCROLL));
if (theComboBox.Images nil) then
itemsFullWidth := (itemsFullWidth + theComboBox.Images.Height);
if (itemsFullWidth > theComboBox.Width) then
begin
itemsFullWidth := (itemsFullWidth + (2 * HORIZONTAL_PADDING));
SendMessage(theComboBox.Handle, CB_SETDROPPEDWIDTH, itemsFullWidth, 0);
end;
finally
c.Free;
end;
end;'TAZ' wrote:I figured it out and I am not sure why I had to do this. The original problem was that setting the dropdown width was fine when the font size was 8. However, I have the font size set to 12. The dropdown width did not adjust. That was puzzling.
In my research I came across using a TBitmap to set the text length. It worked.
I am not sure why I had to assign the combo box font to the bitmap and then use the bitmap textwidth to get the proper dropdown width. Very odd.
https://stackoverflo…-without-canvas
See attached.
Thanks.
March 28, 2019 at 5:40 am #59310Support
KeymasterThanks for new demo, I will research it soon.
-
AuthorPosts
- You must be logged in to reply to this topic.