Mega Code Archive

 
Categories / Delphi / Hardware
 

Find out if the mouse button is pressed while moving the mouse

Title: find out if the mouse-button is pressed while moving the mouse Question: How can I find out if the mouse-button is pressed while moving the mouse Answer: See this little paint-programmm. You also can see here how to use a tHeaderControl. Here (the tHeaderControl), I have 4 Items: the first one contasins just the directory I have this article save to (text). The other 3 'are connected to' a timagelist. This tImageList hast 3 bitmaps. 3 rectangles with the colors green, red and blue.By clicking on one of these 3 items of the hedercontrol, I choose the color I want to paint/draw with.If you want the project, email me. Omer Y. Can -- omercan@home.nl unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, ExtCtrls, ImgList; type TForm1 = class(TForm) Image1: TImage; StatusBar1: TStatusBar; HeaderControl1: THeaderControl; ImageList1: TImageList; procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure HeaderControl1SectionClick(HeaderControl: THeaderControl; Section: THeaderSection); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; WColor : tColor; implementation {$R *.DFM} {==============================================================================} procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if (Shift = [ssLeft]) then // begin with Canvas do begin Pen.Color := WColor; Pen.Style := psSolid; Pen.Width := 1; LineTo(X, Y); end; end; end; procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Canvas.MoveTo (X,Y); end; {==============================================================================} procedure TForm1.HeaderControl1SectionClick(HeaderControl: THeaderControl; Section: THeaderSection); begin case Section.Index of 1: WColor := clgreen; 2: WColor := clred; 3: WColor := clBlue; end; end; {==============================================================================} end.