Re-learning gdi+[25]: Tgppen

Source: Internet
Author: User
Tags integer

This example effect chart:

Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Tecanvas, Comctrls;
Type
TForm1 = Class (Tform)
Combobox1:tcombobox;
Combobox2:tcombobox;
Trackbar1:ttrackbar;
Buttoncolor1:tbuttoncolor;
Procedure Formcreate (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Combobox1change (Sender:tobject);
Procedure Combobox2change (Sender:tobject);
Procedure Trackbar1change (Sender:tobject);
Procedure Buttoncolor1click (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj,gdipapi, Typinfo;
Var
StartCap, Endcap:integer;
Linewidth:single = 2;
Linecolor:tgpcolor = aclred;
Procedure Tform1.formcreate (Sender:tobject);
Begin
With Combobox1.items do
Begin
ADD (' Linecapflat ');
ADD (' Linecapsquare ');
ADD (' Linecapround ');
ADD (' Linecaptriangle ');
ADD (' Linecapnoanchor ');
ADD (' Linecapsquareanchor ');
ADD (' Linecaproundanchor ');
ADD (' Linecapdiamondanchor ');
ADD (' Linecaparrowanchor ');
ADD (' Linecapcustom ');
End
Combobox1.itemindex: = 0;
Combobox2.items: = Combobox1.items;
Combobox2.itemindex: = 0;
Trackbar1.showselrange: = False;
Trackbar1.min: = 1;
Trackbar1.max: = 50;
Trackbar1.position: = 2;
Buttoncolor1.symbolcolor: = clred;
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
P:tgppen;
X1,y1,x2,y2:integer;
Begin
G: = Tgpgraphics.create (Canvas.handle);
P: = tgppen.create (0);
G.clear (Makecolor (255,255,255));
X1: = 50;
x2: = ClientWidth-50;
Y1: = clientheight Div 2;
y2: = y1;
P.setcolor (LineColor);
P.setwidth (linewidth);
P.setstartcap (STARTCAP);
P.setendcap (ENDCAP);
G.drawline (p, x1, y1, x2, y2);
G.free;
P.free;
End
Procedure Tform1.combobox1change (Sender:tobject);
Var
I:integer;
Begin
I: = 0;
Case Tcombobox (Sender). ItemIndex of
0:I: = Linecapflat;
1:I: = Linecapsquare;
2:I: = Linecapround;
3:I: = Linecaptriangle;
4:I: = Linecapnoanchor;
5:I: = Linecapsquareanchor;
6:I: = Linecaproundanchor;
7:I: = Linecapdiamondanchor;
8:I: = Linecaparrowanchor;
9:I: = Linecapcustom;
10:I: = Linecapanchormask;
End
If Tcombobox (Sender) = ComboBox1 then startcap: = i;
If Tcombobox (Sender) = ComboBox2 then endcap: = i;
Repaint;
End
Procedure Tform1.combobox2change (Sender:tobject);
Begin
Combobox1change (Sender);
End
Procedure Tform1.trackbar1change (Sender:tobject);
Begin
LineWidth: = trackbar1.position;
Repaint;
End
Procedure Tform1.buttoncolor1click (Sender:tobject);
Begin
LineColor: = Colorreftoargb (Buttoncolor1.symbolcolor);
Repaint;
End
End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.