Have multiple images are put on the form, the mouse randomly click on the image, how to design a process, judge the mouse to click the number of times per image, source code, thank you
CodePudding user response:
Using the image tag value is different, which is to determine the image control of single event, then the number of single to accumulate; Or define an array of image is more convenient,
CodePudding user response:
reference 1st floor yct0605 response: using the image tag value is different, which is to determine the image control of single event, and then the number of single to accumulate; Or define an array of image is more convenient, He is the source code CodePudding user response:
Help me, anyone can CodePudding user response:
A, new construction, to join two Image and Edit Two, define a global variable M1, M2, record the number of two images by mouse click, Three, code: unit Unit1; Interface USES the Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, jpeg, ExtCtrls; Type TForm1=class (TForm) Image1: TImage; Image2: TImage; Edit1: TEdit; Edit2: TEdit; For: TButton; Button2: TButton; Procedure Button1Click (Sender: TObject); Procedure Button2Click (Sender: TObject); Procedure Image1MouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Procedure Image2MouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Procedure FormShow (Sender: TObject); Private {Private declarations} Public {Public declarations} The end; Var Form1: TForm1; M1, M2: integer; Implementation {$R *. DFM} Procedure TForm1. Button1Click (Sender: TObject); The begin The close; The end; Procedure TForm1. Button2Click (Sender: TObject); The begin M1:=0; M2:=0; Edit1. Text:=InttoStr (M1); Edit2. Text:=InttoStr (M2); The end; Procedure TForm1. Image1MouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); The begin M1: M1 +=1; Edit1. Text:=InttoStr (M1); The end; Procedure TForm1. Image2MouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); The begin M2:=M2 + 1; Edit2. Text:=InttoStr (M2); The end; Procedure TForm1. FormShow (Sender: TObject); The begin M1:=0; M2:=0; Edit1. Text:=InttoStr (M1); Edit2. Text:=InttoStr (M2); The end; End. CodePudding user response:
Four, rendering: CodePudding user response:
unit Unit1; Interface USES the Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls ExtCtrls, jpeg. Type TForm1=class (TForm) Image1: TImage; Image2: TImage; Image3: TImage; Image4: TImage; Image5: TImage; Memo1: TMemo; Procedure Image1Click (Sender: TObject); Private {Private declarations} Public {Public declarations} Procedure DispimgClick; The end; Var Form1: TForm1; Img_clicks: array [0.. 4] of Integer; Implementation {$R *. DFM} Procedure TForm1. DispimgClick; Var I: Integer; The begin Memo1. Lines. The Clear; For I:=Low (img_clicks) to High (img_clicks) do The begin Memo1. Lines. The Add (+ IntToStr 'images' (I + 1) +' clicks: + IntToStr (img_clicks [I])) The end; The end; Procedure TForm1. Image1Click (Sender: TObject); The begin Img_clicks [(Sender as TImage). The Tag] :=img_clicks [(Sender as TImage). The Tag] + 1; DispimgClick; The end; End. CodePudding user response:
reference 5 floor lyhoo163 reply: 4, rendering: Work well! CodePudding user response:
I give you write a more general algorithm, need not care about several image element, don't have to write a heap of dead code Type TForm1=class (TForm) Image1: TImage; Image2: TImage; Procedure FormCreate (Sender: TObject); Private {Private declarations} Procedure OnImageClick (sender: TObject); Procedure InitParam (); Public {Public declarations} The end; Var Form1: TForm1; Implementation {$R *. DFM} //image click event Procedure TForm1. OnImageClick (sender: TObject); The begin TImage (sender). The Tag:=TImage (sender). The Tag + 1; TImage (sender). Hint:=Format (' have click % d times, [TImage (sender). The Tag]); The end; //initialization function, mainly used for dynamic binding image click event Procedure TForm1. InitParam (); Var I: integer; The begin For I:=0 to do ControlCount - 1 The begin If not (Controls, [I] is TImage) then continue. TImage (Controls, [I]). ShowHint:=true; nullnullnullnullnullnullnullnull