Recent

Author Topic: [Solved] How to display linetypes in combobox?  (Read 2742 times)

loaded

  • Hero Member
  • *****
  • Posts: 824
[Solved] How to display linetypes in combobox?
« on: July 30, 2021, 07:10:20 am »
Hi All,
I am drawing different types of lines in the application with the following sample code.
How can I visually load the shapes of the drawable line types in the most practical way into the combobox?
I would really appreciate if you can help. Respects.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   y:integer=0;
  4. begin
  5.   inc(y,10); canvas.Pen.Style:=psSolid; canvas.Line(10,y,100,y);
  6.   inc(y,10); canvas.Pen.Style:=psDash; canvas.Line(10,y,100,y);
  7.   inc(y,10); canvas.Pen.Style:=psDashDot; canvas.Line(10,y,100,y);
  8.   inc(y,10); canvas.Pen.Style:=psDashDotDot; canvas.Line(10,y,100,y);
  9.   inc(y,10); canvas.Pen.Style:=psDot; canvas.Line(10,y,100,y);
  10.   ComboBox1.Clear;
  11.   ComboBox1.Items.Add('psSolid');
  12.   ComboBox1.Items.Add('psDash');
  13.   ComboBox1.Items.Add('psDashDot');
  14.   ComboBox1.Items.Add('psDashDotDot');
  15.   ComboBox1.Items.Add('psDot');
  16. end;
« Last Edit: July 30, 2021, 08:39:43 am by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: How to display linetypes in combobox?
« Reply #1 on: July 30, 2021, 08:07:22 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   ComboBox1.Items.Clear;
  4.   ComboBox1.Style := csOwnerDrawVariable;
  5.   ComboBox1.Items.Add('Solid');
  6.   ComboBox1.Items.Add('Dash');
  7.   ComboBox1.Items.Add('DashDot');
  8.   ComboBox1.Items.Add('DashDotDot');
  9.   ComboBox1.Items.Add('Dot');
  10. end;
  11.  
  12. procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);
  13. begin
  14.   case (Control as TComboBox).Items[Index] of
  15.     'Solid': (Control as TComboBox).Canvas.Pen.Style := psSolid;
  16.     'Dash': (Control as TComboBox).Canvas.Pen.Style := psDash;
  17.     'DashDot': (Control as TComboBox).Canvas.Pen.Style := psDashDot;
  18.     'DashDotDot': (Control as TComboBox).Canvas.Pen.Style := psDashDotDot;
  19.     'Dot': (Control as TComboBox).Canvas.Pen.Style := psDot;
  20.   end;
  21.   (Control as TComboBox).Canvas.Pen.Width := 3;
  22.   (Control as TComboBox).Canvas.Pen.Color := clBlack;
  23.   (Control as TComboBox).Canvas.Line(ARect.Left, ARect.Top + (ARect.Height div 2), ARect.Left + 150, ARect.Top + (ARect.Height div 2));
  24.   (Control as TComboBox).Canvas.TextOut(ARect.Left + 160, ARect.Top, (Control as TComboBox).Items[Index]);
  25. end;
Best regards / Pozdrawiam
paweld

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: How to display linetypes in combobox?
« Reply #2 on: July 30, 2021, 08:39:30 am »
paweld, Thank you very much for taking your precious time to reply. that's what i wanted.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: [Solved] How to display linetypes in combobox?
« Reply #3 on: July 30, 2021, 12:50:02 pm »
The unit TChartComboBox in unit TAChartCombos of the TAChart package allows to select a pen style when property Mode is switched to ccmPenStyle. Likewise, you can select a pen width or a brush style when Mode is ccmPenWidth or ccmBrushStyle, respectively.

Since it also allows to select a series pointer style the unit is interweaved with other TAChart units and thus cannot extracted easily.

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: [Solved] How to display linetypes in combobox?
« Reply #4 on: July 30, 2021, 02:08:11 pm »
Thanks a lot wp master, this information was also very good.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018