Solved

TCustomControl & Focusing

Posted on 2004-04-20
12
575 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
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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 33

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now