Solved

TCustomControl & Focusing

Posted on 2004-04-20
12
594 Views
Last Modified: 2010-04-05
I have my VCL derived from TCustomControl. I try to can Focus it.
Added
  ControlState:=ControlState+[csFocusing];
But don't work.
In same time tabbing don't work , too.

What to do to can focused my vcl and to catch SetFocus and KillFocus?

0
Comment
Question by:ginsonic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10868679
usual there should be no problem

-> will do a test
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10868948
did you published the propertys
-tabStop
-tabOrder
??
0
 
LVL 9

Author Comment

by:ginsonic
ID: 10868960
yes!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Accepted Solution

by:
kretzschmar earned 250 total points
ID: 10869158
well, a just ugly sample

unit customcontrol1;

interface

uses
  SysUtils, Classes, Controls, graphics, messages;

type
  tcustomcontrol1 = class(TCustomControl)
  private
  protected
    procedure paint; override;
    procedure wmkillfocus(var message : TMessage); message WM_KILLFOCUS;
    procedure wmsetfocus(var message : TMessage); message WM_SETFOCUS;
  public
    { Public declarations }
  published
    property tabStop;
    property tabOrder;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [tcustomcontrol1]);
end;

procedure tcustomcontrol1.paint;
begin
  inherited;
  canvas.Brush.Color := clRed;
  canvas.FillRect(ClientRect);
  if focused then
    canvas.DrawFocusRect(ClientRect);
end;

procedure tcustomcontrol1.wmkillfocus(var message : TMessage);
begin
  inherited;
  invalidate;
end;

procedure tcustomcontrol1.wmsetfocus(var message : TMessage);
begin
  inherited;
  invalidate;
end;

end.

a better sample may follow

meikl ;-)
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10870174
usually this one works:
but take care that TabStop is False by default.... you have to force it to true in constructor procedure....
unit customcontrol1;

interface

uses
  SysUtils, Classes, Controls;

type
  tcustomcontrol1 = class(TCustomControl)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(Aowner: Tcomponent); override;
    destructor destroy; override;
  published
    { Published declarations }
    property TabStop;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [tcustomcontrol1]);
end;

constructor TCustomControl1.create(Aowner: Tcomponent);
begin
  Inherited Create(Aowner);
  TabStop := True;
end;

destructor TCustomControl1.destroy;
begin

inherited Destroy;
end;

end.
0
 
LVL 9

Author Comment

by:ginsonic
ID: 10870872
meikl ,
I use same code on my VCL, but look like SetFocus and KillFocus events aren't captured.
0
 
LVL 9

Author Comment

by:ginsonic
ID: 10870886
About TabOrder I forgot to set to True into object inspector.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10873985
All you need to do is 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.

type
  TMyCustomControl = class(TCustomControl)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(Aowner: Tcomponent); override;
  published
    { Published declarations }
    property TabStop;
    property TabOrder;
  end;


constructor TMyCustomControl.Create(Aowner: Tcomponent);
begin
  Inherited Create(Aowner);
  TabStop := True;
end;


Shane
0
 
LVL 34

Assisted Solution

by:Slick812
Slick812 earned 250 total points
ID: 10874052
I think that the   SetIme;  and the   ResetIme;   make a diference for all that are derived from a tWinControl -

procedure TMyCusCtrl.WMLButtonUp(var Message: TWMLButtonUp);
begin
inherited;
SetFocus;
end;

procedure TMyCusCtrl.WMSetFocus(var Message: TWMSetFocus);
begin
InValidate;
SetIme; // tells the Form thet a focus has happened
end;

procedure TMyCusCtrl.WMKillFocus(var Message: TWMSetFocus);
begin
InValidate;
ResetIme;
end;
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10877252

   send message WM_NCACTIVATE to the form
0
 
LVL 9

Author Comment

by:ginsonic
ID: 10881604
Solve my problem. All start from: ControlState:=ControlState+[csFocusing]; When I removed all work perfect.
0
 
LVL 9

Author Comment

by:ginsonic
ID: 10881629
Thanks to all for support.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Multiple image collision 13 106
Firemonkey DbLookupComboBox equivalent ? 2 77
How to save the image in the .cds File ClientDataSet? 1 41
TAction.OnAfterExecute? 2 31
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question