本来分这么少的问题很少光顾,但看楼主点名要给麻子大侠加1分,心里实在是不愿意大侠的自尊被如此折磨,只好自不量力地挡挡刀了!<br><br><br>&gt;&gt;单击工程中的某一个窗体及其窗体下的控件时执行同一段代码<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> Label1: TLabel;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure FormClick(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> protected<br><br> public<br> { Public declarations }<br> pre:Boolean;<br> procedure Dothis;<br> procedure AppMessage(var Msg: TMsg; var Handled: Boolean);<br><br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>{ TForm1 }<br><br>procedure TForm1.Dothis;<br>begin<br> Label1.Caption:='Dothis';<br> pre:=True;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> if Pre then<br> begin<br> ShowMessage('Button1 is Click');<br> Label1.Caption:='AfterDothis';<br> Pre:=False;<br> end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> if Pre then<br> begin<br> ShowMessage('Button2 is Click');<br> Label1.Caption:='AfterDothis';<br> Pre:=False;<br> end;<br>end;<br><br>procedure TForm1.FormClick(Sender: TObject);<br>begin<br> if Pre then<br> begin<br> ShowMessage('Form1 is Click');<br> Label1.Caption:='AfterDothis';<br> Pre:=False;<br> end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> Pre:=False;<br> Application.OnMessage:=AppMessage;<br>end;<br><br>procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);<br>begin<br> if Msg.message = WM_LBUTTONDOWN then<br> begin<br> if Screen.ActiveForm=self then<br> dothis;<br> end;<br>end;<br><br>end.<br><br>澄清一点:写代码就是苦力,没有懒可以偷,有些代码即使重复一千边你也要重复。<br>