Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TCustomControl & Focusing

Posted on 2004-04-20
12
Medium Priority
?
638 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
Independent Software Vendors: 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 1000 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 23

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 1000 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

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!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

670 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