?
Solved

Custom edit control

Posted on 1999-12-13
12
Medium Priority
?
219 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:ON031699
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 1

Expert Comment

by:JoeBooth
ID: 2277888
Did you make sure that CanFocus is set to TRUE?  By default, it would be false, hence preventing the control from getting focus....
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2278011
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
 
LVL 1

Author Comment

by:ON031699
ID: 2278021
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 10

Accepted Solution

by:
ptmcomp earned 300 total points
ID: 2278227
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
 
LVL 1

Author Comment

by:ON031699
ID: 2278322
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
 
LVL 1

Author Comment

by:ON031699
ID: 2278469
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
 

Expert Comment

by:aacrg
ID: 2279178
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
 
LVL 1

Author Comment

by:ON031699
ID: 2280147
Hi aacrq
How can i change that so the text stop blinking.
0
 

Expert Comment

by:aacrg
ID: 2280241
..
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
 

Expert Comment

by:aacrg
ID: 2280249
Sorry - I forgot:
  inherited CreateParams(Params);
(First row of second method)
0
 
LVL 1

Author Comment

by:ON031699
ID: 2280703
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
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2284972
Thanks.
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.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses

593 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