Solved

Moving controls on a form at runtime

Posted on 1997-05-28
2
165 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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