TCustomControl的子类如何处理方向键?处理WM——KEY消息怎么也找不到,看了一下帮助,说是Tab,方向键等都不产生键盘事件,晕啊。谁能帮帮忙?
当这个组件被聚焦的时候,按下左键画个元,右键画一个方!55555555555555~~~~~~~救火~~~~~~~~~~
当这个组件被聚焦的时候,按下左键画个元,右键画一个方!55555555555555~~~~~~~救火~~~~~~~~~~
解决方案 »
- “FreeOnTerminate := True;” 但线程执行结束后为什么没有释放?
- 问:做软件的(特别是Delphi),用 AMD 的好还是 Intel 的好,近期想配一台电脑
- 设置断点的键盘按钮是啥?
- 新手问个问题
- 求助:如何将资源中的HTM页面(含图片)读入TWEBBROWSER?
- 三个小问题,帮忙解释一下哦,谢谢
- SendMessage发送消息的一点问题!
- 开始用DELPHI做MIS了,问兄弟们几个问题。
- 巨好答的问题,答详细就给分
- 菜鸟问题:如何建立一个无窗口单元,包含若干函数供其他窗口调用
- 如何让MDI父窗口底色显示一一幅位图????
- 请问如何将DBgrid控件的行和列颠倒,即第一列显示固定表头信息,同时将第一行按照数据库查询数据动态生成,谢谢????????
Shift: TShiftState);
begin
if ( Key = vk_Down ) or ( Key = vk_Up ) then
begin
if Key = vk_Down then
begin
if LstSelections.Row < LstSelections.RowCount - 1 then
LstSelections.Row := LstSelections.Row + 1;
end
else
begin
if LstSelections.row > 0 then
LstSelections.Row := LstSelections.row - 1;
end;
Key := 0;
end;
end;
var Handled: Boolean);
begin
if (Msg.message = WM_KEYDOWN) then
ShowMessage(Format('%d', [Msg.wParam]));
end;
这个有用么?
用
SetWindowLong
TShapeType = (stNone, stEllipse, stRectangle); TMyControl = class(TCustomControl)
private
FIsFocus: Boolean;
FShapeType: TShapeType;
FFillColor: TColor;
procedure WMLButtonDown(var Message: TWMMButtonDown); message WM_LBUTTONDOWN;
procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TWMSetFocus); message WM_KILLFOCUS;
procedure WMGetDlgCode(var Message: TMessage); message WM_GETDLGCODE;
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
end;constructor TMyControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FFillColor := clWhite;
TabStop := True;
end;procedure TMyControl.Paint;
var
R: TRect;
begin
with Canvas do
begin
DrawFrameControl(Handle, ClientRect, DFC_BUTTON, DFCS_BUTTONPUSH);
R := ClientRect;
if FIsFocus then
begin
InflateRect(R, -2, -2);
DrawFocusRect(R);
end; if FShapeType <> stNone then
begin
Canvas.Brush.Color := FFillColor;
InflateRect(R, -2, -2);
case FShapeType of
stEllipse: Ellipse(R);
stRectangle: Rectangle(R);
end;
end;
end;
end;procedure TMyControl.WMGetDlgCode(var Message: TMessage);
begin
Message.Result := DLGC_WANTARROWS or DLGC_WANTTAB;
end;procedure TMyControl.WMKeyDown(var Message: TWMKeyDown);
begin
case Message.CharCode of
VK_LEFT, VK_UP: FShapeType := stEllipse;
VK_RIGHT, VK_DOWN: FShapeType := stRectangle;
VK_TAB: FFillColor := RGB(Random(255), Random(255), Random(255));
else
Exit;
end;
Invalidate;
end;procedure TMyControl.WMKillFocus(var Message: TWMSetFocus);
begin
FShapeType := stNone;
FIsFocus := False;
Invalidate;
end;procedure TMyControl.WMLButtonDown(var Message: TWMLButtonDown);
begin
SetFocus;
end;procedure TMyControl.WMSetFocus(var Message: TWMSetFocus);
begin
FIsFocus := True;
FShapeType := stRectangle;
Invalidate;
end;
procedure TWinControl.CNKeyDown(var Message: TWMKeyDown);
var
Mask: Integer;
begin
with Message do
begin
Result := 1;
UpdateUIState(Message.CharCode);
if IsMenuKey(Message) then Exit;
if not (csDesigning in ComponentState) then
begin
if Perform(CM_CHILDKEY, CharCode, Integer(Self)) <> 0 then Exit;
Mask := 0;
case CharCode of
VK_TAB:
Mask := DLGC_WANTTAB;
VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN:
Mask := DLGC_WANTARROWS;
VK_RETURN, VK_EXECUTE, VK_ESCAPE, VK_CANCEL:
Mask := DLGC_WANTALLKEYS;
end;
if (Mask <> 0) and
(Perform(CM_WANTSPECIALKEY, CharCode, 0) = 0) and
(Perform(WM_GETDLGCODE, 0, 0) and Mask = 0) and
(GetParentForm(Self).Perform(CM_DIALOGKEY,
CharCode, KeyData) <> 0) then Exit;
end;
Result := 0;
end;
end;
这个就明白了
begin
Message.Result := DLGC_WANTARROWS or DLGC_WANTTAB;
end;
呵呵。爽死 !!!!!!!谢谢myy()。