Board index » delphi » Color of caption of TButton

Color of caption of TButton

Hi. I want whenever user moves mouse pointer over a button, color of that
button change to blue.
I tried with font and also brush properties of button but I couldn't do.
How can I do that?
Regards, Naser
 

Re:Color of caption of TButton


Quote
Naser wrote:
> Hi. I want whenever user moves mouse pointer over a button, color of that
> button change to blue.
> I tried with font and also brush properties of button but I couldn't do.
> How can I do that?
> Regards, Naser

TButton will ignore the color properties, use a TBitBtn instead.

To get the effect you want I suggest creating a descendant of TBitBtn and
handling these two messages,

CM_MOUSEENTER {set color in this message}
CM_MOUSELEAVE {restore color in this message}

type
  TMyBitBtn = class(TBitBtn)
  private
    OldColor: TColor;
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;

procedure TMyBitBtn.CMMouseEnter(var Message: TMessage);
begin
  OldColor := Font.Color;
  Font.Color := clBlue;
end;

procedure TMyBitBtn.CMMouseLeave(var Message: TMessage);
begin
  Font.Color := OldColor;
end;

Maybe create a rollover color property so it doesn't always have to be blue.

Re:Color of caption of TButton


thanx. But TBitBtn can't get focus. I mean user can't select TBitBtn by Tab
or arrow keys!
Is that problem solvable?
regards,
Naser

Quote
"Mauro Patino" <M-Pat...@govst.edu> wrote in message

news:3B5C271F.38D1C9D@govst.edu...
Quote
> Naser wrote:

> > Hi. I want whenever user moves mouse pointer over a button, color of
that
> > button change to blue.
> > I tried with font and also brush properties of button but I couldn't do.
> > How can I do that?
> > Regards, Naser

> TButton will ignore the color properties, use a TBitBtn instead.

> To get the effect you want I suggest creating a descendant of TBitBtn and
> handling these two messages,

> CM_MOUSEENTER {set color in this message}
> CM_MOUSELEAVE {restore color in this message}

> type
>   TMyBitBtn = class(TBitBtn)
>   private
>     OldColor: TColor;
>     procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
>     procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;

> procedure TMyBitBtn.CMMouseEnter(var Message: TMessage);
> begin
>   OldColor := Font.Color;
>   Font.Color := clBlue;
> end;

> procedure TMyBitBtn.CMMouseLeave(var Message: TMessage);
> begin
>   Font.Color := OldColor;
> end;

> Maybe create a rollover color property so it doesn't always have to be
blue.

Re:Color of caption of TButton


Quote
Naser wrote:
> thanx. But TBitBtn can't get focus. I mean user can't select TBitBtn by Tab
> or arrow keys!
> Is that problem solvable?
> regards,
> Naser

Yes it can.  The TBitBtn is a window control, it can receive focus.  Your
probably thinking of a TSpeedButton.

Re:Color of caption of TButton


Oops.  "With a TSpeedButton" should read "With a TSpeedButton you can't".

--
Thanks,
Jon.

Quote
"Jon Scott" <jesc...@email.com> wrote in message news:3b5c6709$2_1@dnews...
> ?

> Don't understand why you think you can't focus on a TBitBtn.  With a TSpeedButton, but TButton or
> TBitBtn you can.  TBitBtn has TabStop & TabOrder properties.

> --
> Thanks,
> Jon.

> "Naser" <n_fad...@yahoo.com> wrote in message news:3b5c4c71_2@dnews...
> > thanx. But TBitBtn can't get focus. I mean user can't select TBitBtn by Tab
> > or arrow keys!
> > Is that problem solvable?
> > regards,
> > Naser

Re:Color of caption of TButton


?

Don't understand why you think you can't focus on a TBitBtn.  With a TSpeedButton, but TButton or
TBitBtn you can.  TBitBtn has TabStop & TabOrder properties.

--
Thanks,
Jon.

Quote
"Naser" <n_fad...@yahoo.com> wrote in message news:3b5c4c71_2@dnews...
> thanx. But TBitBtn can't get focus. I mean user can't select TBitBtn by Tab
> or arrow keys!
> Is that problem solvable?
> regards,
> Naser

Re:Color of caption of TButton


Sorry it was my mistake :)
Thank you very much.

Quote
"Naser" <n_fad...@yahoo.com> wrote in message news:3b5c4c71_2@dnews...
> thanx. But TBitBtn can't get focus. I mean user can't select TBitBtn by
Tab
> or arrow keys!
> Is that problem solvable?
> regards,
> Naser

> "Mauro Patino" <M-Pat...@govst.edu> wrote in message
> news:3B5C271F.38D1C9D@govst.edu...
> > Naser wrote:

> > > Hi. I want whenever user moves mouse pointer over a button, color of
> that
> > > button change to blue.
> > > I tried with font and also brush properties of button but I couldn't
do.
> > > How can I do that?
> > > Regards, Naser

> > TButton will ignore the color properties, use a TBitBtn instead.

> > To get the effect you want I suggest creating a descendant of TBitBtn
and
> > handling these two messages,

> > CM_MOUSEENTER {set color in this message}
> > CM_MOUSELEAVE {restore color in this message}

> > type
> >   TMyBitBtn = class(TBitBtn)
> >   private
> >     OldColor: TColor;
> >     procedure CMMouseEnter(var Message: TMessage); message
CM_MOUSEENTER;
> >     procedure CMMouseLeave(var Message: TMessage); message
CM_MOUSELEAVE;

> > procedure TMyBitBtn.CMMouseEnter(var Message: TMessage);
> > begin
> >   OldColor := Font.Color;
> >   Font.Color := clBlue;
> > end;

> > procedure TMyBitBtn.CMMouseLeave(var Message: TMessage);
> > begin
> >   Font.Color := OldColor;
> > end;

> > Maybe create a rollover color property so it doesn't always have to be
> blue.

Other Threads