Recent

Author Topic: Line Type Combo Box  (Read 2469 times)

SandyG

  • Full Member
  • ***
  • Posts: 114
Line Type Combo Box
« on: July 26, 2025, 07:45:30 pm »
I have seen a few code samples to do a combo box that shows the various line types for drawing displayed as a graphic. Then while creating a component with a type of
Code: Pascal  [Select][+][-]
  1. TPenStyle
it shows up correctly in the property inspector.

Is this dropdown something that I can use directly in my program? I have looked at the various LCL components and can't seem to find one that does this without creating it manually.

Trying to not recreate if it already exists.




wp

  • Hero Member
  • *****
  • Posts: 13212
Re: Line Type Combo Box
« Reply #1 on: July 26, 2025, 07:53:40 pm »
There is one in TAChart: TChartCombobox (mixed style, i.e. besides pen styles it can also display brush styles and TAChart series pointer symbols).

jamie

  • Hero Member
  • *****
  • Posts: 7308
Re: Line Type Combo Box
« Reply #2 on: July 26, 2025, 08:19:33 pm »
I am not aware of any like that, but I guess you could look in the editors for the IDE which may bring in a lot more than you need.

  I wrote my own in a CAD style app to do that using the Tcombobox in ownerDraw mode.

Jamie
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7308
Re: Line Type Combo Box
« Reply #3 on: July 26, 2025, 10:22:55 pm »
Here is something I just put together based close to what I had made elsewhere.

This should give you an idea of how to make a Pen style selection drop down.

The only true wisdom is knowing you know nothing

SandyG

  • Full Member
  • ***
  • Posts: 114
Re: Line Type Combo Box
« Reply #4 on: July 27, 2025, 01:33:18 am »
Here is something I just put together based close to what I had made elsewhere.

This should give you an idea of how to make a Pen style selection drop down.

I think I saw this example in another thread, was trying to avoid doing the extra work. Will take a look and see if I can get it going!

Thanks

Sandy


SandyG

  • Full Member
  • ***
  • Posts: 114
Re: Line Type Combo Box
« Reply #5 on: July 27, 2025, 01:35:28 am »
There is one in TAChart: TChartCombobox (mixed style, i.e. besides pen styles it can also display brush styles and TAChart series pointer symbols).

I'll have to take a look, seems like both would be useful as part of the Regular LCL. Might be something I'll just add to the BGRAControls as that's sorta' what I'm messing with right now.

Thanks for the direction!

Sandy

jamie

  • Hero Member
  • *****
  • Posts: 7308
Re: Line Type Combo Box
« Reply #6 on: July 27, 2025, 03:44:02 am »
Here is something I just put together based close to what I had made elsewhere.

This should give you an idea of how to make a Pen style selection drop down.

I think I saw this example in another thread, was trying to avoid doing the extra work. Will take a look and see if I can get it going!

Thanks

Sandy

I doubt you saw that example, I just took the screen shot you supplied and made one look like that, it's something close to what I did in an app.

 You can see how to get an index from the EMUM type to store it simpler.

Have fun.

jamie
The only true wisdom is knowing you know nothing

simsee

  • Full Member
  • ***
  • Posts: 226
Re: Line Type Combo Box
« Reply #7 on: July 27, 2025, 05:15:19 pm »
@Jamie: Your example is very interesting. I tried adapting it to TBrushStyle, but it's proving less trivial than expected because the BrushStyle settings on the rectangle drawn inside the combobox items interfere with the item highlighting (the text of the selected item disappears). I've tried various tricks, without solving the problem. Any suggestions?

Here's the code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  2.   ARect: TRect; State: TOwnerDrawState);
  3. Var
  4. R:TRect;
  5.   Procedure DrawBox;
  6.    begin
  7.      With COntrol As TCombobox do
  8.       Begin
  9.        Canvas.Pen.Color := clBlack;
  10.        Canvas.Pen.Width:=1;
  11.        Canvas.Pen.Style := psSolid;
  12.        Canvas.Brush.Color:=clBlack;
  13.        Canvas.Brush.Style:=TBrushStyle(ord(Index));
  14.        InflateRect(R,-1,-1);
  15.        R.Width := R.Width Div 3;
  16.        Canvas.Rectangle(R);
  17.       end;
  18.    end;
  19.    PRocedure DrawName;
  20.    var
  21.     S:String;
  22.    Begin
  23.      if Index < 0 then exit;
  24.     With Control as TComboBox do
  25.      Begin
  26.        WriteStr(S,TPenStyle(ord(Index)));
  27.        Canvas.Textout(R.Right+4,Arect.Top,S);
  28.      End;
  29.    end;
  30. begin
  31.   R:= aRect;
  32.   DrawBox;
  33.   DrawName;
  34. end;
  35.  
  36. procedure TForm1.FormCreate(Sender: TObject);
  37. var
  38.  L:Integer;
  39. begin
  40.   For L := 0 To Ord(High(TBrushStyle)) do
  41.     ComboBox1.Items.Add('');
  42. end;  
« Last Edit: July 27, 2025, 06:04:33 pm by simsee »

SandyG

  • Full Member
  • ***
  • Posts: 114
Re: Line Type Combo Box
« Reply #8 on: July 27, 2025, 07:38:38 pm »
This was the example I thought it was...

https://forum.lazarus.freepascal.org/index.php/topic,55595.0.html

Will try this one out as well. Might dig around in the Lazarus codebase to see what they did as well once I get a bit of time.

Sandy

simsee

  • Full Member
  • ***
  • Posts: 226
Re: Line Type Combo Box
« Reply #9 on: July 27, 2025, 09:41:24 pm »
There is one in TAChart: TChartCombobox (mixed style, i.e. besides pen styles it can also display brush styles and TAChart series pointer symbols).

Thanks Wp, I wasn't aware of this component. However, it seems its height isn't adjustable. Is that true? I need the combo to be taller...

EDIT: It can be set at run time as follows:

Code: Pascal  [Select][+][-]
  1. ChartComboBox1.Style:=csOwnerDrawVariable;
  2. ChartComboBox1.ItemHeight:=40;
« Last Edit: July 28, 2025, 12:07:26 am by simsee »

wp

  • Hero Member
  • *****
  • Posts: 13212
Re: Line Type Combo Box
« Reply #10 on: July 27, 2025, 11:57:02 pm »
There is one in TAChart: TChartCombobox (mixed style, i.e. besides pen styles it can also display brush styles and TAChart series pointer symbols).
it seems its height isn't adjustable. Is that true? I need the combo to be taller...
The Height of the TChartCombobox, like any TCombobox with Style=csOwnerDrawFixed, is determined by the value of the ItemHeight property

simsee

  • Full Member
  • ***
  • Posts: 226
Re: Line Type Combo Box
« Reply #11 on: July 28, 2025, 12:07:00 am »
Thanks wp. In the meantime, I realized this and corrected my previous post.

wp

  • Hero Member
  • *****
  • Posts: 13212
Re: Line Type Combo Box
« Reply #12 on: July 28, 2025, 12:22:27 am »
I had just tested it: It works also with the default csOwnerDrawFixed Style. And the ItemHeight property is accessible also in the object inspector

jamie

  • Hero Member
  • *****
  • Posts: 7308
Re: Line Type Combo Box
« Reply #13 on: July 28, 2025, 12:30:05 am »
I just removed the last one I placed here and attached a more refined version.

Also, would like to know why there is a bsPattern and bsImage, both seem to require the same bitmap?

The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 13212
Re: Line Type Combo Box
« Reply #14 on: July 28, 2025, 02:05:15 am »
I just removed the last one I placed here and attached a more refined version.

Also, would like to know why there is a bsPattern and bsImage, both seem to require the same bitmap?
Study the pen_brush example coming with Lazarus. Click on the ? buttons to learn more about the details.

 

TinyPortal © 2005-2018