Recent

Author Topic: [KOL] Combobox custom height  (Read 4645 times)

VAV

  • New member
  • *
  • Posts: 8
[KOL] Combobox custom height
« on: March 12, 2021, 03:57:53 pm »
Hi everyone, I'm a newbie, I'm working in not so popular IDE called HiAsm, which uses KOL library, I needed to change Combobox height (height of the edit box, not the dropdown list), and encountered that it's not normally changeable and depends on the font size. I searched for a solution on HiAsm, FreePascal and Delphi resources and as I understood this issue is pretty much universal and to solve it I have to change the Style to one of OwnerDraw options (something like csOwnerDrawEditableFixed in Lazarus/LCL or coOwnerDrawFixed in KOL I believe?) and ItemHeight to let's say 14.

But my IDE doesn't provide a GUI way to set the Style property like in Lazarus. I need to add a piece of inline code which will overwrite the Combobox properties. Unfortunately I'm very new to this, I'm not good with writing code yet and I failed to write it myself in this case.

May I ask for an example of the code that does that in Lazarus, so I could try to port it, or a code that naturally works with KOL, that would be even better.
Thank you.

/edited.
« Last Edit: March 13, 2021, 09:12:07 pm by VAV »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Combobox custom height
« Reply #1 on: March 12, 2021, 04:04:30 pm »
On most widgetsets the height of the combobox editbox is not customisable, whether or not you specify the control Style as csOwnerDrawXXX.
The LCL uses the native widgets for nearly all its controls, by design.
« Last Edit: March 12, 2021, 04:06:09 pm by howardpc »

wp

  • Hero Member
  • *****
  • Posts: 12800
Re: Combobox custom height
« Reply #2 on: March 12, 2021, 04:16:27 pm »
In Windows (maybe also on other widgetsets - I did not test this), you can select the Combobox.Style csOwnerDrawFixed or csOwnerDrawEditableFixed. Despite their name the items are still painted automatically (unless you do not provide an OnDrawItem handler), but the Combobox.ItemHeight now can be changed and this allows you to adjust the height of the combobox to any value (but you also alter the spacing between the dropdown items this way).

The difference between the two styles is that you can only select items from the dropdown list when Style is csOwnerDrawFixed, but you can also type text when Style is csOwnerDrawEditableFixed.

VAV

  • New member
  • *
  • Posts: 8
Re: Combobox custom height
« Reply #3 on: March 12, 2021, 04:45:05 pm »
In Windows (maybe also on other widgetsets - I did not test this), you can select the Combobox.Style csOwnerDrawFixed or csOwnerDrawEditableFixed. Despite their name the items are still painted automatically (unless you do not provide an OnDrawItem handler), but the Combobox.ItemHeight now can be changed and this allows you to adjust the height of the combobox to any value (but you also alter the spacing between the dropdown items this way).

The difference between the two styles is that you can only select items from the dropdown list when Style is csOwnerDrawFixed, but you can also type text when Style is csOwnerDrawEditableFixed.
Yes that's exactly what I'm trying to do. May I ask for an example of the code, procedure etc. please? I'm very new to this and I'm trying to write it myself but fail.
I'm on Windows.

wp

  • Hero Member
  • *****
  • Posts: 12800
Re: Combobox custom height
« Reply #4 on: March 12, 2021, 04:58:32 pm »
There's nothing to write. Just put a TCombobox on the form, go to the object inspector (the two-column list of properties and values at the left), find the property "Style", its default value is "csDropdown". Click on this row, the field converts to a combobox. Select the value "csOwnerDropDownFixed" from the list. Then find property "ItemHeight", click on the row again and type the value "20" into the value field. When you press ENTER the height of the combobox on the form increases to 20 pixels.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Combobox custom height
« Reply #5 on: March 12, 2021, 04:59:49 pm »
Try to set AutoSize := False. This is what I do when I need to use TComboBox as a cell editor in any grid. Combo has the same height as a grid row.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

VAV

  • New member
  • *
  • Posts: 8
Re: Combobox custom height
« Reply #6 on: March 12, 2021, 09:14:28 pm »
There's nothing to write. Just put a TCombobox on the form, go to the object inspector (the two-column list of properties and values at the left), find the property "Style", its default value is "csDropdown". Click on this row, the field converts to a combobox. Select the value "csOwnerDropDownFixed" from the list. Then find property "ItemHeight", click on the row again and type the value "20" into the value field. When you press ENTER the height of the combobox on the form increases to 20 pixels.
Yes I'm sorry, I needed to specify that I'm working not exactly in Lazarus but another Object Pascal IDE with FPC on Windows (it uses KOL library as a similar alternative to VCL and LCL), I tried to solve the issue with combobox height there but it doesn't have a built-in solution for that (no Style property in the GUI). The only option is to manually add a piece of inline code to redraw (if it's a correct term in English) the combobox element. So I need a general example how to set the Style and ItemHeight in the code, I'll try to adapt it then. I was able to fix some other issues with combobox this way such as inability to make it flat, but failed to do the same for the height.
Hope it makes sense.
« Last Edit: March 12, 2021, 09:30:49 pm by VAV »

wp

  • Hero Member
  • *****
  • Posts: 12800
Re: Combobox custom height
« Reply #7 on: March 12, 2021, 09:58:05 pm »
Sorry, I don't know KOL and cannot help you. Why didn't you tell us your working environment in the first post?

VAV

  • New member
  • *
  • Posts: 8
Re: Combobox custom height
« Reply #8 on: March 12, 2021, 11:12:16 pm »
Sorry, I don't know KOL and cannot help you. Why didn't you tell us your working environment in the first post?
I'm sorry for the confusion, it's called HiAsm, it's not as popular but as a newbie I happened to choose it for my work and I'm stuck with it currently, need to finish the project that's almost done. I didn't want to focus on the IDE, because I didn't try to find a direct solution for KOL, I knew the answer would be the same as yours, sadly the community is dead and there are almost zero people who can help with HiAsm and I already tried every available source. So instead I'm trying to find a basic example of the code for related Pascal/Delphi environments to try to port it. I already had success with another issue by using custom inline code with OnPaint method, I'm trying to solve this the similar way.
Is it possible to give an example of the code which sets Style and ItemHeight, it'll be more than enough for me, I'll try to adapt it myself.

VTwin

  • Hero Member
  • *****
  • Posts: 1227
  • Former Turbo Pascal 3 user
Re: Combobox custom height
« Reply #9 on: March 12, 2021, 11:24:26 pm »
From my experience it is wise to accept the default LCL controls and not fight them. Cross platform considerations and OS updates (as Windows high dpi or dark mode) throw monkey wrenches at you.
« Last Edit: March 12, 2021, 11:28:24 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 15.3.2: Lazarus 3.8 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 3.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 3.8 (64 bit on VBox)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Combobox custom height
« Reply #10 on: March 12, 2021, 11:49:53 pm »
Hi!

KOL --> ask Thaddy https://forum.lazarus.freepascal.org/index.php?action=profile;u=43552

He was one of them who  created that stuff.

Winni

VAV

  • New member
  • *
  • Posts: 8
Re: Combobox custom height
« Reply #11 on: March 13, 2021, 12:56:29 am »
Hi!

KOL --> ask Thaddy https://forum.lazarus.freepascal.org/index.php?action=profile;u=43552

He was one of them who  created that stuff.

Winni

Wow! Honestly I didn't expect to find people that work with KOL here.
I'm sorry for all the confusion. I thought my only option was to ask for a LCL/Lazarus solution and then port it.
Looks like I chose the wrong forum section after all. I see that I can probably remove my first post which might remove the thread so I can create a new one in a proper forum section and formulate it better? Or the moderators might move the thread. What should I do? (I'm not able to open Thaddy's profile as it returns me an error "You are not allowed to access this section").

Anyway, I edited my original post to make it more clear.
« Last Edit: March 13, 2021, 03:09:26 am by VAV »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Combobox custom height
« Reply #12 on: March 13, 2021, 01:19:39 am »
Hi

Send him a private message:

Top of the page:

"My Messages" --> "Send a message"

Winni

wp

  • Hero Member
  • *****
  • Posts: 12800
Re: Combobox custom height
« Reply #13 on: March 13, 2021, 01:24:09 am »
I see that I can probably remove my first post which might remove the thread so I can create a new one in a proper forum section and formulate it better?
No do not delete the first post. If it's no longer there, the following points are meaningless.

dseligo

  • Hero Member
  • *****
  • Posts: 1507
Re: Combobox custom height
« Reply #14 on: March 13, 2021, 01:42:45 am »
Is it possible to give an example of the code which sets Style and ItemHeight, it'll be more than enough for me, I'll try to adapt it myself.
Here you go, hope it helps:
Code: Pascal  [Select][+][-]
  1. Combobox1.Style:=csOwnerDrawFixed;
  2. Combobox1.ItemHeight:=36;

 

TinyPortal © 2005-2018