Reputation: 180
I have a problem with left click on TPanel and TAdvPanel (TMS Components) also. If I set DragMode = dmAutomatic
then Left click doesn't work. Right click works.
procedure TMain_Form.Panel_Item_01MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
{ whatever I type here nothing happen, even showmessage wont popup - no effect}
end;
if Button = mbRight then
begin
{ here code works fine }
end;
end;
It seems simple to me but ... can't found the way how to resolve this issue and call procedure on left button click. Guys, any idea?
Upvotes: 2
Views: 5930
Reputation: 85
There is a one trick with this to "check" if the eq. TButton with a DragMode=TDragMode.dmAutomatic. Simply check the time distance between OnMouseLeave and OnMouseEnter... The code:
uses DateUtils;
var Time1:TDateTime;
procedure TForm4.Button2MouseLeave(Sender: TObject);
begin
Memo1.Lines.Add('OnMouseLeave');
Time1:=Now;
end;
procedure TForm4.Button2MouseEnter(Sender: TObject);
var
A:Integer;
begin
A:=MillisecondsBetween(Time1,Now);
Memo1.Lines.Add('OnMouseEnter '+IntToStr(A));
end;
Then see that with clicking the TButton the time distance is always 0. Another events results with a larger time distance.
I know that it's a not clear approach to solve this problem, but Embarcadero sometimes makes me berserk...
Upvotes: 1
Reputation: 180
Guess problem is resolved now.
If you set TPanel component DragMode to dmAutomatic seems it can't trigger the OnClick event. However, when I set same TPanel DragMode to dmManual it can run OnClick even.
Problem solved with little help of OnMouseEnter even where I manually set Panel_Item_01.DragMode := dmManual; Now it can recognize left mouse button and preserve TPanel DragDrop functionality.
Here is complete code :
procedure TMain_Form.Panel_Item_01MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
Panel_Item_01.DragMode := dmManual;
{ ..rest of code.. }
end;
if Button = mbRight then
begin
Panel_Item_01.DragMode := dmAutomatic;
{ ..rest of code.. }
end;
end;
procedure TMain_Form.Panel_Item_01MouseEnter(Sender: TObject);
begin
Panel_Item_01.DragMode := dmManual;
end;
procedure TMain_Form.Panel_Item_01MouseLeave(Sender: TObject);
begin
Panel_Item_01.DragMode := dmAutomatic;
end;
Upvotes: 4