Solved

TCustomControl & Focusing

Posted on 2004-04-20
12
602 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
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!

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

734 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