Solved

Help with custom component with keypress

Posted on 2002-04-05
4
332 Views
Last Modified: 2010-04-04
I have written a graphical component which derives from the TPanel base class. All is great, but I need foir this to accept keys from ther user when it has focus.
This base class does not accept focus or keypress. I have tryed compiling it as a twincontrol (no luck) and as a tcustomcomponent(no luck) and as a tcustomcontrol(no luck).

I would greatly appreciate any assistance with this.
0
Comment
Question by:bobspencerr
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 200 total points
ID: 6922348
here's some sample code:

type
  TFocusPanel = class(TPanel)
  private
    procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
  protected
    procedure WndProc(var Message: TMessage); override;
  end;


procedure TFocusPanel.CMFocusChanged(var Message: TCMFocusChanged);
begin
     with Message do
       if Sender is TPanel then
          if Sender = Self then
             Caption:='got focus'
          else
             Caption:='lost focus'
       else Caption:='lost focus';
     inherited;
end;

procedure TFocusPanel.WndProc(var Message: TMessage);
begin
     case Message.Msg of
       WM_LBUTTONDOWN,
       WM_LBUTTONDBLCLK: Windows.SetFocus(Handle);
     end;
     inherited WndProc(Message);
end;
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6922403
listening
0
 

Author Comment

by:bobspencerr
ID: 6922534
Sir,
I thank you for your assistance. I spent 24 hours straight on this section alone.

You deserve the points and greatfully given.

Bob Spencer.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6922542
tnx for the A :)
I've spent 10 minutes on it :) (have a bit of component making experience)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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