[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 810
  • Last Modified:

Change VK_Left press key action into my VCL

I have a VCL derived from TCutomControl. When I press VK_UP, VK_Down, VL_Left or VK_Right the result is that my VCL change his focus and jump to next control. What to do to use these keys into my VCL and not to change the focus? I have tried untill now into keypress but no result.
0
ginsonic
Asked:
ginsonic
  • 2
1 Solution
 
shaneholmesCommented:
You need to handle the wm_GetDlgCode message as shown below:

TMyCustomControl = class(TCustomControl)
private
 { Private declarations }
 procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
 end;


procedure TMyCustomControl.WMGetDlgCode( var Msg: TWMGetDlgCode );
begin
  inherited;
  Msg.Result := dlgc_WantArrows;   // Control will handle arrow keys
end;


You need to ensure that your control can receive the focus. Descending
from TCustomControl is the first step, which you've done. The next step is
publishing the TabStop & TabOrder properties, so users can navigate to your control
with the keyboard. The third step is calling SetFocus in the MouseDown
method.

Just add the TabStop- and TabOrder-property to the published section
of your control and in the constructor you assign true to the
TabStop-property.


Shane
0
 
ginsonicAuthor Commented:
Thanks for support! Work now :)
0
 
shaneholmesCommented:
<SMILE>
Your Welcome!

Shane
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now