Form Focus...

Hey all,
  Quick question.  I have a form that doesn't have a titlebar.  Instead I have a custom image with a label over it that is dragable.  Is there anyway that I can make the font color of that label change when the form loses focus or gains focus, and if so how?
QxmAsked:
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.

mhervaisCommented:
listening
0
mhervaisCommented:
listening
0
simonetCommented:
Just do that (change the font) on the OnActive (= form gains focus) and OnDeactivate (=form loses focux) events of the form.

Yours,

Alex
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

QxmAuthor Commented:
That didn't work.  I did just what you said and it stayed the same color.
0
simonetCommented:
>OnActive

Sorry. That was supposed to read OnActivate. The event handlers should look something like this:

procedure TForm1.FormActivate(Sender: TObject);
begin
   label1.font.color := clActiveCaption;
end;

procedure TForm1.FormDeactivate(Sender: TObject);
begin
   label1.font.color := clInactiveCaption;
end;

Make sure you are leaving your form accordingly. Also make sure you are setting the color of the FONT property of the TLabel component.

Yours,

Alex
0
QxmAuthor Commented:
That didn't work.  I did just what you said and it stayed the same color.
0
mottorCommented:
Use Application events:

procedure TForm1.FormDeactivate(Sender: TObject);
begin
  Label1.Font.color := clBlue;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  Label1.Font.color := clred;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnActivate := FormActivate;
  Application.OnDeActivate := FormDeActivate;
end;

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
LischkeCommented:
Qxm, you need to call TLabel.Update after you changed the color...

Ciao, Mike
0
AttarSoftwareCommented:
Or, you can declare a handler for the WM_NCACTIVATE message

  private
    procedure WMNCA( var msg : tMessage ) ; message WM_NCACTIVATE ;


....

procedure tForm1.WMNCA( var msg : tMessage ) ;
begin
  if( msg.wParam = 1 ) then
    label1.font.color := clActiveCaption
  else
    label1.font.color := clInactiveCaption ;
  {and as Mike says ;}
  label1.Update ;
end ;

I have forms with owner-draw captions and that seems to work fine for me in all instances...

(You maight like to look at the help for WM_NCACTIVATE, as my PC is offline at the moment, so I cannot check whether it is wParam that gets the flag for active or inactive...  might be lParam)

Anyways,  good luck...

Tim.
0
simonetCommented:
Can you post your code, please? There's no way the suggested solution can be wrong.

Alex
0
karooCommented:
Qxm,
try this
regards Ben

....
private
  procedure ColorLabel(Sender: TObject);
....

procedure TForm1.FormCreate(Sender: TObject);
begin
  Screen.OnActiveFormChange:= ColorLabel;
end;

procedure TForm1.ColorLabel(Sender: TObject);
begin
  ...color change code here
end;
0
AttarSoftwareCommented:
Surely using the Application.OnActivate solution is fine, so long as you have only one form in the application...  If you have many child windows being created from the same form type (such as in an MDI app), then only the last created form will perform the on activate function?

Probably wrong, I usually am ;O)

Tim.
0
QxmAuthor Commented:
Thanks alot mottor!

That worked great for me.

0
simonetCommented:
How is that different from the answer I first suggested?

Alex
0
QxmAuthor Commented:
I really don't know but your did not work for me.  I tried several times and it just didn't.  I then tried motter's and it worked the very first time.
0
mottorCommented:
Thanks Qxm,

Alex,
you didn't explain that he must use Application's event OnActivate, not the Form's OnActivate.
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.