çizgi çizecek component

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
cfyasar
Üye
Mesajlar: 169
Kayıt: 31 Oca 2005 05:18
Konum: izmir

çizgi çizecek component

Mesaj gönderen cfyasar »

çizgi çizmek için bir bileşen hazırlıyorum.

Kod: Tümünü seç

unit line;

interface

uses
  Windows, Messages, Graphics, SysUtils, Classes, Controls;

type
 
  TLine = class(TGraphicControl)
  private
    { Private declarations }
    FLineData: word;
    function GetLineWidth: Integer;
    function GetLineColour: TColor;
    function GetLineData: word;
    procedure SetLineWidth(const NewWidth: Integer);
    procedure SetLineColour(const NewColour: TColor);
    procedure SetLineData(const NewData: Word);
  protected
    { Protected declarations }
    procedure Paint; override;
  public
    { Public declarations }
  published
    { Published declarations }
    property Data : word  read FlineData write SetLineData;  
    property LineColour : TColor read GetLineColour write SetLineColour;
    property LineWidth : Integer read GetLineWidth write SetLineWidth;
    property OnClick;
    property OnMouseDown;
    property OnMouseUp;
  end;

procedure Register;

implementation

function TLine.GetLineWidth: Integer;
begin
  Result := Canvas.Pen.Width;
end;

function TLine.GetLineColour: TColor;
begin
  Result := Canvas.Pen.Color;
end;

function TLine.GetLineData: word;
begin
   Result := FLineData;
end;

procedure TLine.SetLineData(const NewData: Word);
begin
   if NewData <> FLineData then
  begin
    FLineData := NewData;
    Invalidate; // redraws the component
  end;
end;

procedure TLine.SetLineWidth(const NewWidth: Integer);
begin
  if NewWidth <> Canvas.Pen.Width then
  begin
    Canvas.Pen.Width := NewWidth;
    Invalidate; // redraws the component
  end;
end;

procedure TLine.SetLineColour(const NewColour: TColor);
begin
  if NewColour <> Canvas.Pen.Color then
  begin
    Canvas.Pen.Color := NewColour;
    Invalidate;
  end;
end;

procedure TLine.Paint;
begin
  inherited;
  // buraya mousedown ve mouseup kodlarını eklemem lazım
  Canvas.Moveto(x1,y1);
  Canvas.Lineto(x2,y2);
end;
line için yazılan paint işlevinde x1 ve y1 değerlerini farenin tıklandığı noktayı, x2 ve y2 değerine de farenin bırakıldığı noktayı almak istiyorum. mousedown ve mouse up olaylarını paint işlevine nasıl ekleyecem?
öğrenmek, zorlukları yenmektir.
Kullanıcı avatarı
husonet
Admin
Mesajlar: 2962
Kayıt: 25 Haz 2003 02:14
Konum: İstanbul
İletişim:

Mesaj gönderen husonet »

Kod: Tümünü seç

    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
    procedure DoMouseDown(var Message: TWMMouse; Button: TMouseButton;
      Shift: TShiftState);
    procedure DoMouseUp(var Message: TWMMouse; Button: TMouseButton);
Bence Windows message bildirimleriyle yakalaayabilirsin.

Delphinin hiyerarşinden TControl sınıfını bir incele istersen.

Kolay Gelsin...

Gazete manşetleri
* DİKKAT :Lütfen forum kurallarını okuyalım ve uyalım...!
* Warez,crack vs. paylaşımı kesinlikle yasaktır.
Cevapla