🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: cn.bbs.comp.program
1 messages
1 total messages Started by ���ܵ�Сʨ Thu, 07 May 1998 00:00
Delphi�л���Ӧ�ü���
#854
Author: ���ܵ�Сʨ
Date: Thu, 07 May 1998 00:00
255 lines
13804 bytes
    DelphiΪ������ṩ��һ�����Ļ�ͼ����,��CANVAS(����)��,
Delphi�еĺܶ�ؼ������д�����,����߿�������Щ�ؼ��ı�����
������ػ�ͼ���������˵������������ĻЧ����γɹ�̡�

    CANVAS�ر���֪ʶ

    1.����CANVAS���ԵĿؼ�
    ����CANVAS���ԵĿؼ���:TBitmap,TComboBox,TDBComboBox,TDB
Grid,TDBListBox,TDr ectoryListBox,TDrawGrid,TFileListBox,TFo
rm,THeaderControl,TImage,TListBox,TOuli ne,TPaintBox,TPrinte
r,TStatusBar,TStringGrid�ȡ�
    2.CANVAS���Լ�����
    ����ƪ������,ʡ�Բ����ʽ˵��,������ο��ĺ����Delp
hi�����ļ�,����ֻ�г�������
    canvas.rectangle():������       pen.color:���廭����ɫ
    roundrect():��Բ�Ǿ���          pen.width:���廭�ʿ��
    arc():������(�����)            brush.color:���������ɫ
    chord():������(���)            textout():�ڹ̶�λ�����
�ַ�
    pie:������                      textwidth:ȡ�ַ�߶�
    polygon():����������          textheight:ȡ�ַ���
    polyline():�������(�����)     font.color:ָ��������ɫ
    Pixels():ָ���̶����ص���ɫֵ   font.size:ָ�������С
    moveto():ָ���������           Ellipse():��Բ����Բ
    lineto():ָ�������յ�

    3.ʹ��CANVASע������
    �����ڽ����ػ�ʱ,�����ϵ�ͼ����ʧ,���統���ڽ�����С��
�����»ָ�ʱ,�ͻ����𻭲���ͼ�����ʧ�����⵱�ո����г���ʱ,
����Ҳ���������»���,��������ڻ��ƴ���֮ǰ�ڻ����ϻ�ͼ,����
���ں󽫲�����ʾ��ͼ�񡣱�����TForm1.FormCreate()�¼��н���
������ͼ��������ͽ�͵�,�������ڴ��¼��н��л���������׼����
��,�������û��ʵ���ɫ�Ϳ�ȵȡ�

    CANVASӦ�þ���

    1.Ϊ�ؼ�������Ӱ��ͶӰЧ��:
    ��ԭ�������øÿؼ��ĸ��ؼ�����FORM�������������ؼ���CA
NVAS,����Ҫ���εĿؼ���Χ�ʵ������ͼ��,ͨ����������ɫ�ĺ���
����ʹ�ؼ�����Χ��ͼ����Ϊһ��,�γ�������Ӿ�Ч��������
ʱ��Ҫ��ݱ����οؼ���TOP��LEFT��WIDTH��HEIGHT������,ȷ����
Ҫ���ߵ������յ����,����������۱����οؼ�λ�ü��ߴ����
�仯,�����Ա�֤���Ƶ�ͶӰ����ӰЧ�������ڴ����н������
��ť,Ȼ���ڰ�ť2�Ͱ�ť3��CLICK�¼���������´���,֮���°�
ť2��ť3,ʹ��ť1�γ�ͶӰ����ӰЧ��
    procedure TForm1.Button2Click(Sender:TObject);
    var
    x,y,i:integer;
    begin
    x:=0;y:=0;
    form1.canvas.pen.width:=1;
    for i:=0 to 8 do
    begin
    form1.canvas.pen.color:=$00a0a0a0;
    form1.canvas.moveto(Button1.left+Button1.width+x,Button1
.top+y);
    form1.canvas.lineto(Button1.left+Button1.width+x,Button1
.top+button1.heigh+ y);
    form1.canvas.pen.color:=$00606060;
    form1.canvas.moveto(Button1.left+x,Button1.top+Button1.h
eight+y);
    form1.canvas.lineto(Button1.left+Button1.width+x,Button1
.top+button1.heigh+ y);
    x:=x+1;
    y:=y+1;
    end;
    end;
    procedure TForm1.Button3Click(Sender:TObject);
    var
    x,y,i:integer;
    begin
    x:=0;y:=0;
    form1.canvas.pen.width:=1;
    for i:=0 to 8 do
    begin
    form1.canvas.pen.color:=$00404040;
    form1.canvas.moveto(Button1.left+Button1.width+x,Button1
.top+8);
    form1.canvas.lineto(Button1.left+Button1.width+x,Button1
.top+button1.heigh+ 8);
    form1.canvas.moveto(Button1.left+8,Button1.top+Button1.h
eight+y);
    form1.canvas.lineto(Button1.left+Button1.width+8,Button1
.top+button1.heigh+ y);
    x:=x+1;
    y:=y+1;
    end;
    end;

    2.Ϊ�ؼ����ϱ߿�
    Delphi���кܶ�ؼ��ޱ߿�����,����CANVAS����Ϊ����ؼ���
�ӱ߿�,ʹ������������������ʱ,���ȶ�������ʵ���ɫ�����ʵ�
���(�߿���),Ȼ����polyline()��������Ӧ�ؼ���λ�á��ߴ�
�Զ���λ�Ľ����,һ�ο����һ���̶���Ⱦ��εĻ��ƹ��������
��Ҫ������ɫ���߾�������Ч��ı߿�,�ɶ�ζ��廭����ɫ,������
��Ķ������,ͨ��������ھ��ε���ɫ��ʵ������Ч��ı߿����
�����������ڴ����а���������ť,�ֱ���MOUE MOVE�¼����������
����,ÿ������Ƶ���Ӧ�İ�ť��ʱ,�ð�ť�ͻ����������ɫ�ı߿�
; ������Ƶ����ڿհ״�ʱ,�򴰿ڻ�������Եı���,���������
ʾЧ��
    procedure TForm1.Button1MouseMove(Sender:TObject; Shift:
TShiftState; X,Y:It eger);
    begin
    form1.repaint;
    form1.Canvas.pen.color:=clGreen;
    form1.Canvas.pen.width:=5;
    form1.Canvas.polyline([point(Button1.left,Button1.top),
    point(Button1.left+Button1.width,Button1.top),
    point(Button1.left+Button1.width,Button1.top+Button1.hei
ght),
    point(Button1.left,Button1.top+Button1.height),
    point(Button1.left,Button1.top)]);
    end;
    procedure TForm1.Button2MouseMove(Sender:TObject; Shift:
TShiftState; X,Y:In teger);
    begin
    form1.repaint;
    form1.Canvas.pen.color:=clBlue;
    form1.Canvas.pen.width:=5;
    form1.Canvas.polyline([point(Button2.left,Button2.top),
    point (Button2.left+Button2.width,Button2.top),
    point(Button2.left+Button2.widthButton2.top+But 
    Delphi�л���Ӧ�ü���
    point(Button2.left,Button2.top+Button2.height),
    point(Button2.left,Button2.top)]);
    end;
    procedure TForm1.FormMouseMove(Sender:TObject; Shift:TSh
iftState; X, Y:Inte ger);
    begin
    form1.repaint;
    form1.Canvas.pen.color:=clRed;
    form1.Canvas.pen.width:=3;
    form1.Canvas.polyline([point(0,0),point(form1.width-10,0
),
    point(form1.width-10,form1.height-30),point(0,form1.heig
ht-30),point(0,0)]
    end;

    3.Ϊͼ�ΰ�ť������ؼ���װ��̬������
    �˴���Ҫʹ��CANVAS���ַ���ʾ����,��������Ƶ�ָ���ؼ�
��ʱ,������Χ�ʵ�λ����ʾ��Ӧ���ַ�;������뿪ʱͨ��ͼ��
�Ƕ���ʹ�ַ���ʧ,Ҳ����ʹ��һ���򵥵�������ɼ�form1.repai
nt,���������ʹFORM1�ڵ����пؼ�ȫ�����»���,�Ӷ�������ԭ
����ʾ���ַ�ؼ��� MouseMove()�¼�����ʵ�����Ϲ��ܡ������
�ڴ����а���������ť���������´���,����֮������Ƶ���Ӧ��
ť��ʱ,�ͻ������Ϸ���ʾ��Ӧ����ʾ��Ϣ,����Ƶ����ڿհ״����
�ڴ��ڵ����½���ʾ"OK"����
    procedure TForm1.Button1MouseMove(Sender:TObject;Shift:T
ShiftState;X, Y:Ine ger);
    begin
    form1.repaint;
    form1.Canvas.brush.color:=clGreen;
    form1.Canvas.font.size:=8;
    form1.Canvas.font.color:=$1200ffff;
    form1.Canvas.TextOut(Button1.left,Button1.top-15,��OPEN 
FILE��);
    end;
    procedure TForm1.Button2MouseMove(Sender:TObject;Shift:T
ShiftState;X,Y:Inte ger);
    begin
    form1.repaint;
    form1.Canvas.font.size:=8;
    form1.Canvas.brush.color:=clRed;
    form1.Canvas.font.color:=$1200ffff;
    form1.Canvas.TextOut(Button2.left,Button2.top-15,`EXIT')
;
    end;
    procedure TForm1.FormMouseMove(Sender:TObject;Shift:TShi
ftState;X, Y:Intege r);
    begin
    form1.repaint;
    form1.Canvas.font.size:=12;
    form1.Canvas.brush.color:=clBlue;
    form1.Canvas.font.color:=$00ffffff;
    form1.Canvas.TextOut(0,form1.height-50,��OK��);
    end;

    4.�µ����ƶ���Ļ��ͼ��
    ��CANVAS���������ƶ���Ļ�Ļ�ԭ����:����ѡ��һ������Ϊ
�����Ŀؼ�,���� FOR��IMAGE,Ȼ����һ�������ɫ�����������,��
�����Ĺ̶�λ����ʾһ����������ǰ����ɫ�̶��ߴ���ַ�,�� TI
MER�ؼ��ж�ʱ����ı���ʾ�ַ��λ�á�����ԭ��λ�õ��ַ�
�����Զ���ʧ,������Ҫ���������ɫ��ͬ��ɫ���������Ƕ��ಿ��,
ʵ��ƽ������Ļ�ƶ�Ч��ʵ��ͼ���ƶ��ķ���:���ȶ���Bitmap��
��Rect�����,�ڳ������н׶ν���Bitmap��R ect����,����Bitmap
��װ��ָ����ͼ���ļ�,ͬʱ�Ѷ���Bitmapװ��Rect������,ʵ��ͼ��
����ʾ����Timer �ؼ��ж�ʱ����ı�Rect�����ֵ,�����������
ɫ��ͬ��������������ͼ�񲿷�,ʵ��ͼ���ƽ���ƶ�������������
��ʵ�ֵ��ַ��ͼ���ƶ�����,��Ч��ƽ�����κ���˸�򶶶�����,
�Ӿ�Ч��ܺ�,���Ҳ���Ҫ���Ƚ����ؼ�,��ȫ�ɳ������ʵ�֡�
    ��̾���:�ڴ����а���ʱ��ؼ�TIMER1��ͼ���IMAGE1,����TR
ECT��TBITMAP�ͱ�������FormCreate��Timer1Timer�¼��а�������
����,��������֮�󼴻���ͼ����г������¶��ϵ��ƶ���Ļ��ͼ��
Ч��,���Ӷ�����ʧ,Ȼ�����´ӵײ����֡�
    var  {�������}
    Form1:TForm1;
    x,tt,l,h:integer;
    pic:Trect;
    map:Tbitmap;
    {���嶯����ʾ����}
    procedure TForm1.Timer1Timer(Sender:TObject);
    begin
    x:=x-1;
    tt:=tt-1;
    if x<-160 then
    x:=image1.height+20;
    tt:=x+80;
    image1.Canvas.font.size:=18;
    image1.Canvas.font.color:=$1200ffff;
    image1.Canvas.TextOut(10,x,��OK ��Ļ�ƶ���ʾ��);
    image1.Canvas.font.size:=12;
    image1.Canvas.font.color:=$120000ff;
    image1.Canvas.TextOut(20,x+50,�������ɫЧ����ʾ��);
    l:=image1.Canvas.textwidth(�������ɫЧ����ʾ��);
    h:=image1.Canvas.textheight(�������ɫЧ����ʾ��);
    image1.Canvas.pen.color:=clGreen;
    image1.Canvas.moveto(20,h+x+50-2);
    image1.Canvas.lineto(20+l,h+x+50-2);
    pic.topleft.x:=30;
    pic.topleft.y:=tt;
    pic.bottomright.x:=pic.topleft.x+100;
    pic.bottomright.y:=pic.topleft.y+80;
    image1.canvas.stretchdraw(pic,map);
    image1.Canvas.pen.color:=clGreen;
    image1.Canvas.moveto(0,pic.topleft.y+80);
    image1.Canvas.lineto(pic.topleft.x+100,pic.topleft.y+80)
;
    end;
    {�������ö�����ֵ}
    procedure TForm1.FormCreate(Sender:TObject);
    begin
    timer1.enabled:=true;
    timer1.Interval:=10;
    x:=image1.height+20;
    tt:=x+80;
    form1.repaint;
    image1.Canvas.brush.color:=clGreen;
    pic:=Rect(0,0,image1.width,image1.height);
    image1.Canvas.FillRect(pic);
    pic:=Rect(-1,-1,1,1);
    map:=Tbitmap.create;
    map.loadfromfile(��d:\Windows\256color.bmp��)
    image1.canvas.stretchdraw(pic,map);
    end;
    ���Ϸ�����������Windows 95��Delphi2.0�����µ���ͨ��
--
 ________ _____          _____        ______________  _____ 
 ___  __ \___(_)________ ___(_)       __  ___/___  /_ ___(_)
 __  /_/ /__  / ___  __ \__  /        _____ \ __  __ \__  / 
 _  ____/ _  /  __  /_/ /_  /         ____/ / _  / / /_  /  
 /_/      /_/   _  .___/ /_/          /____/  /_/ /_/ /_/   
                /_/                                         

�� ��Դ:���ϴ�С�ٺ���Ϣ����վ bbs.nju.edu.cn��[FROM: hsia.nju.edu.cn]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads