Custom edit control

Hi!
Im trying to create a custom edit control in delphi 4. Im deriving my new control from TWinControl, but i cant get it to receive focus. How is that done.
LVL 1
ON031699Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JoeBoothCommented:
Did you make sure that CanFocus is set to TRUE?  By default, it would be false, hence preventing the control from getting focus....
0
ptmcompCommented:
You have to react on the WM_SETFOCUS and WM_KILLFOCUS messages. The feedback for the focus you can give with antoher appearance of your component. (e.g. blue color). When your control is focused there is csFocused in the ControlState.

Regards, ptm.
0
ON031699Author Commented:
CanFocus is True.
I have a WM_SETFOCUS and a WM_KILLFOCUS in order to construct and destroy a caret, but they are never called.
When i run the program nothing happens when i click in the control.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

ptmcompCommented:
If you want the control to set the focus to itself on click, you have to write:
  ...
  protected
    procedure Click; override;
  ...
  end;

implementation

procedure MyControl.Click;
begin
  inherited Click;
  SetFocus;
end;

Regards, ptm.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ON031699Author Commented:
Well, it works but im thinking about its the prober method to do it because, the standard vcl components in delphi start with the focus if its the only control on the form, but mine does not, it have to clicked first....
I wonder why?
0
ON031699Author Commented:
I have sorted it out now, it has todo with the TabStop, True or False :)
If you post your answer i can give you the points, but i would always like to ask another question.
When i have the control in a form and it is aligned to client, when i resize the window the whole control is invalidated and thereby causes the whole control to be redrawn. It makes the tekst in the window blink.
Why?
0
aacrgCommented:
Hi ON
It's cause of the window class styles CS_VREDRAW and CS_HREDRAW. And also beacuase your control has probably not csOPAQUE in ControlStyle.

0
ON031699Author Commented:
Hi aacrq
How can i change that so the text stop blinking.
0
aacrgCommented:
..
protected
  procedure TMyControl.CreateParams(var Params: TCreateParams); override;
end;

implementation

constructor TMyControl.Create...
begin
  inherited Create...
  ControlStyle:=ControlStyle + [csOpaque];
  ...
end;

procedure TMyControl.CreateParams(var Params: TCreateParams);
begin
  Params.WindowClass.style := Params.WindowClass.style and not (CS_VREDRAW or CS_HREDRAW);
end;
0
aacrgCommented:
Sorry - I forgot:
  inherited CreateParams(Params);
(First row of second method)
0
ON031699Author Commented:
Thanks, its working :)))
Actually the points should go to ptmcomp for the first answer, cause he answered my first question. I dont know how to give you points too.
0
ptmcompCommented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.