Go Premium for a chance to win a PS4. Enter to Win

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

TCustomControl & Focusing

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
ginsonic
Asked:
ginsonic
2 Solutions
 
kretzschmarCommented:
usual there should be no problem

-> will do a test
0
 
kretzschmarCommented:
did you published the propertys
-tabStop
-tabOrder
??
0
 
ginsonicAuthor Commented:
yes!
0
Industry Leaders: 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!

 
kretzschmarCommented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
ginsonicAuthor Commented:
meikl ,
I use same code on my VCL, but look like SetFocus and KillFocus events aren't captured.
0
 
ginsonicAuthor Commented:
About TabOrder I forgot to set to True into object inspector.
0
 
shaneholmesCommented:
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
 
Slick812Commented:
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
 
Ivanov_GCommented:

   send message WM_NCACTIVATE to the form
0
 
ginsonicAuthor Commented:
Solve my problem. All start from: ControlState:=ControlState+[csFocusing]; When I removed all work perfect.
0
 
ginsonicAuthor Commented:
Thanks to all for support.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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