|
Processing the events in the application
When TFormDesigner is active it processes all messages of the form and controls itself and standard events of the form and controls are not fired. If you want to process some events in your application without deactivating TFormDesigner just lock it by the Lock procedure. After it all messages will be sent to the OnMessage event and can be processed by your code. The code below allows to choose a point to placing the new label on the form. The form contains the protected AddNewLabel button.
procedure TForm1.AddNewLabelClick(Sender: TObject);
begin
// locking the designer
FormDesigner1.Lock;
end;
procedure TForm1.FormDesigner1Message(Sender: TObject; var Msg: TMsg);
begin
// processing the message
with Msg do
// if message is mouse down and user clicks the form...
if (Message=WM_LBUTTONDOWN) and (hwnd=Handle) then
begin
// ...we create the new label...
with TLabel.Create(Self) do
begin
Left:=LoWord(lParam);
Top:=HiWord(lParam);
Caption:='New label';
Parent:=Self;
end;
// ...and unlock the designer
FormDesigner1.Unlock;
end;
end;
Note that the passed message has a Windows message format (see TMsg in Delphi and MSG in WinAPI).
|