The custom dashed style relies on an array whose elements represent the length of the dotted line between the lines and the size of the array as if there were no limits;
This example uses an array of six elements, which means that the dotted line has three segments and three intervals.
This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Extctrls, Comctrls;
Type
TForm1 = Class (Tform)
Panel1:tpanel;
Trackbar1:ttrackbar;
Trackbar2:ttrackbar;
Trackbar3:ttrackbar;
Trackbar4:ttrackbar;
Trackbar5:ttrackbar;
Trackbar6:ttrackbar;
Procedure Formcreate (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Trackbar1change (Sender:tobject);
Procedure Trackbar2change (Sender:tobject);
Procedure Trackbar3change (Sender:tobject);
Procedure Trackbar4change (Sender:tobject);
Procedure Trackbar5change (Sender:tobject);
Procedure Trackbar6change (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Var
DASHARR:ARRAY[0..5] of single;
Procedure Tform1.formcreate (Sender:tobject);
Const
n = 100;
Begin
Trackbar1.max: = n;
Trackbar2.max: = n;
Trackbar3.max: = n;
Trackbar4.max: = n;
Trackbar5.max: = n;
Trackbar6.max: = n;
Trackbar1.position: = n Div 2;
Trackbar2.position: = n Div 2;
Trackbar3.position: = n Div 2;
Trackbar4.position: = n Div 2;
Trackbar5.position: = n Div 2;
Trackbar6.position: = n Div 2;
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
P:tgppen;
Rect:trect;
Begin
G: = Tgpgraphics.create (Canvas.handle);
P: = Tgppen.create (aclred, 4);
Dasharr[0]: = TRACKBAR1.POSITION/10;
DASHARR[1]: = TRACKBAR2.POSITION/10;
DASHARR[2]: = TRACKBAR3.POSITION/10;
DASHARR[3]: = TRACKBAR4.POSITION/10;
DASHARR[4]: = TRACKBAR5.POSITION/10;
DASHARR[5]: = TRACKBAR6.POSITION/10;
P.setdashpattern (@DashArr, Length (Dasharr)); {Set dashed line}
G.drawline (p, 0, 0, clientwidth-panel1.width, clientheight);
Rect: = Bounds (0, 0, clientwidth-panel1.width, clientheight);
Inflaterect (Rect,-30,-30);
G.drawellipse (P, makerect (rect));
P.free;
G.free;
End
Procedure Tform1.trackbar1change (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.trackbar2change (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.trackbar3change (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.trackbar4change (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.trackbar5change (Sender:tobject);
Begin
Repaint;
End
Procedure Tform1.trackbar6change (Sender:tobject);
Begin
Repaint;
End
End.