I have a Delphi XE2 project having components like Label1, BitBtn1 and Image1. I have implemented form dragging without the caption bar writing the following code:
private
{ Private declarations }
procedure WMNCHitTest(var Msg: TWMNCHitTest) ; message WM_NCHitTest;
and
procedure TMainForm.WMNCHitTest(var Msg: TWMNCHitTest) ;
begin
inherited;
if Msg.Result = htClient then Msg.Result := htCaption;
end;
In my form, the Image1.OnMouseMove and Label1.OnClick events are compulsory for my project, but they are not working. How can I drag the form from the client area except the Image1 and Label1 areas? I can do one thing that I may use one TPanel, but it will destroy the GlassFrame and SheetOfGlass properties of my form.
You will need to use the position information that is included in the
WM_NCHITTESTmessage. Use that to determine whether or not there is a control present at that point. For example you could use theControlAtPosmethod.This will allow dragging only if you have clicked on a point on the form at which there is no control present. You may wish to use an alternative criteria, but use of
Msg.Posis the key idea.