Solved

Moving controls on a form at runtime

Posted on 1997-05-28
2
153 Views
Last Modified: 2010-04-06
I want to write a program where the user can put any ordinary control on a form and move it. The problem is that any mouse / keyboard messages goes to the control and not to the form. I consulted the Lischner "Undocumented Delphi" but found no answer. Anybody any ideas ?
0
Comment
Question by:arnoldu
2 Comments
 

Author Comment

by:arnoldu
ID: 1336635
Edited text of question
0
 
LVL 1

Accepted Solution

by:
sleach earned 50 total points
ID: 1336636
Make a universal event handler/procedure that is common to all controls.  Then at the time you add the component, assing the handler to the event.  Example:
 
NewControl.OnMouseMove := MouseMove;

The Universal event handler can get/set top & left properties so as to move them to wherever you want on the form.  You could also use the OnMouseDown event if you rather.
Hope this helps.

{Example Procedure}
procedure TForm1.MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
Top, Left:  Integer;
begin
{Get top & Left positions of the control}
Top := (sender as TControl.top);
Left := (sender as TControl.left);

{Set Top & Left postions of the control}
(sender as TControl.top) := 10;
(sender as TControl.Left) := 5;
end;

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now