TsComboBoxEx Question

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #59293
    Support
    Keymaster

      Which version of the Delphi do you uses?

      I have tried the CB_SETDROPPEDWIDTH message with TsComboBoxEx component, it works well in my test.

      #59298
      TAZ
      Participant

        Delphi 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.

        #59302
        Support
        Keymaster

          Thank you for the demo.

          Positions of controls are correct there?

          Look what I see on my side.

          #59303
          TAZ
          Participant

            Well, 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.

            #59306
            TAZ
            Participant

              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.

              'TAZ' wrote:

              Well, I feel silly. I will get back to you.

              #59307
              TAZ
              Participant

                One 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.

                #59310
                Support
                Keymaster

                  Thanks for new demo, I will research it soon.

                Viewing 7 posts - 1 through 7 (of 7 total)
                • You must be logged in to reply to this topic.