I'm using D2009. I have a component derived from TWinControl to which I'd like to add mouse panning. I see that there's a new control style, csPannable, and a new control state, csPanning. I've been looking at the vcl source to try to figure it out, but so far I'm a bit lost. Does anyone know of any documentation for this? Any suggestions or links greatly appreciated!
+1
A:
In the same unit that defines TWinControl, you have the implementation of TControl. See how the mouse events and procedures are defined. You can try to capture mouse messages in your component.
Try this:
In private declarations:
procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
In implementation you can do something like this
procedure TPanControl.WMLButtonDown(var Message: TWMLButtonDown);
begin
Self.Color := clYellow;
end;
procedure TPanControl.WMLButtonUp(var Message: TWMLButtonUp);
begin
Self.Color := clbtnFace;
end;
procedure TPanControl.WMMouseMove(var Message: TWMMouseMove);
var
State : TKeyboardState;
begin
GetKeyboardState(State);
if ((State[VK_LBUTTON] And $80) <> 0) then begin
Self.Color := clOlive;
end;
end;
Test some variations. With this simple code you can catch mouse events. In these procedures you can launch mouse events or do something to create Pan effect.
Neftalí
2009-07-28 14:05:42
As mentioned I'm trying to interface with the built in panning support.
MarkF
2009-07-28 14:27:35