Topic: Script for button to change label (caption) to BOLD

Hello MVD, does anyone know how to implement this via script?  What I want is the caption of the button, (THE TEXT ON THE BUTTON),
to change to BOLD, when you hover over with the mouse.  Sort of to make the form responsive, modern look.  If anyone has a sample of
a script please feel free to share.  Thanks!

Re: Script for button to change label (caption) to BOLD

Never mind, I found a way to do it.  Don't know if it's the best approach but it works as expected.  Here's the code:

// BUTTON 1        ====================================== ///////////////
procedure Form1_Button5_OnMouseEnter (Sender: TObject);
begin
   Form1.PanelBtn1.Visible := TRUE;
   Form1.Button5.Font.Style := (fsBold);
   Form1.Button5.Font.Size := 13;
end;

procedure Form1_Button5_OnMouseLeave (Sender: TObject);
begin
   Form1.PanelBtn1.Visible := FALSE;
   Form1.Button5.Font.Style := 0;
   Form1.Button5.Font.Size := 12;
 end;

Re: Script for button to change label (caption) to BOLD

derek wrote:

Hi Gonpublic2k,
Sorry - didn't see your earlier post.
One way I've used before is to have 2 buttons, overlaying each other;  one has the caption in normal, the other has the caption in bold (not very sophisticated but I like to keep things simple - LOL!).
One other thing you might also consider is to change the pointer when the mouse enters the button - in my attached example, I change it from an 'arrow' to a 'hand' (this is a standard feature and requires no script - it's in the button object properties - additional - cursor).
Regards,
Derek.

Excellent as always Derek, will consider your solution and the cursor hand thing, I've forgotten about that, that's awesome.  Thanks!!

4 (edited by derek 2018-09-21 18:23:29)

Re: Script for button to change label (caption) to BOLD

Hi Gonpublic2k,
Sorry - didn't see your earlier post.
One way I've used before is to have 2 buttons, (almost) overlaying each other (I set the one button 1 pixel to the left and 1 pixel lower) and then one button has the caption in normal, the other has the caption in bold (not very sophisticated but I like to keep things simple - LOL!).
One other thing you might also consider is to change the pointer when the mouse enters the button - in my attached example, I change it from an 'arrow' to a 'hand' (this is a standard feature and requires no script - it's in the button object properties - additional - cursor).
So the affect when mousing over, is that it turns bold, it looks like it's being clicked and the pointer changes.
Please have a look at the attachment - you can see it working far better than I've explained it!!
Regards,
Derek.
oops!  I think I attached the wrong thing - here it is again!

Post's attachments

Attachment icon buttons.zip 860.08 kb, 390 downloads since 2018-09-21 

Re: Script for button to change label (caption) to BOLD

derek wrote:

Hi Gonpublic2k,
Sorry - didn't see your earlier post.
One way I've used before is to have 2 buttons, (almost) overlaying each other (I set the one button 1 pixel to the left and 1 pixel lower) and then one button has the caption in normal, the other has the caption in bold (not very sophisticated but I like to keep things simple - LOL!).
One other thing you might also consider is to change the pointer when the mouse enters the button - in my attached example, I change it from an 'arrow' to a 'hand' (this is a standard feature and requires no script - it's in the button object properties - additional - cursor).
So the affect when mousing over, is that it turns bold, it looks like it's being clicked and the pointer changes.
Please have a look at the attachment - you can see it working far better than I've explained it!!
Regards,
Derek.
oops!  I think I attached the wrong thing - here it is again!

Thanks mate!

6 (edited by derek 2018-09-22 12:31:01)

Re: Script for button to change label (caption) to BOLD

Hi Again Gonpublic2k,
Following on from my previous post, perhaps I should have explained that I often use images instead of buttons because they can be more intuitive.  However, they are 'static' even when clicked which is why I overlay the 2 identical images on top of each and then off-set one very slightly - when it's clicked, it then 'moves' slightly, as if it has been clicked like a button.
Attached is a simple example.
Perhaps this gives you a couple of more ideas.
Regards,
Derek.

Post's attachments

Attachment icon buttons 2.zip 758.65 kb, 423 downloads since 2018-09-22 

Re: Script for button to change label (caption) to BOLD

derek wrote:

Hi Again Gonpublic2k,
Following on from my previous post, perhaps I should have explained that I often use images instead of buttons because they can be more intuitive.  However, they are 'static' even when clicked which is why I overlay the 2 identical images on top of each and then off-set one very slightly - when it's clicked, it then 'moves' slightly, as if it has been clicked like a button.
Attached is a simple example.
Perhaps this gives you a couple of more ideas.
Regards,
Derek.

Excellent!  Very ingenious, thanks again Derek.

Re: Script for button to change label (caption) to BOLD

Just occurred to me that a much easier and more efficient way to achieve the same effect is simply on 'mouse down' to get the script to move the image a small amount and then on 'mouse up' to move it back again - so no need for overlaying a second image - much cleaner!
Also, if on 'mouse down' you script it to move relative to it's starting position, if you subsequently redesign your form and place the image elsewhere, there is no code to change.
I'm a bit embarrassed I didn't think to do it that way ages ago sad
Derek

Post's attachments

Attachment icon buttons 3.zip 742.69 kb, 447 downloads since 2018-09-22 

Re: Script for button to change label (caption) to BOLD

derek wrote:

Just occurred to me that a much easier and more efficient way to achieve the same effect is simply on 'mouse down' to get the script to move the image a small amount and then on 'mouse up' to move it back again - so no need for overlaying a second image - much cleaner!
Also, if on 'mouse down' you script it to move relative to it's starting position, if you subsequently redesign your form and place the image elsewhere, there is no code to change.
I'm a bit embarrassed I didn't think to do it that way ages ago sad
Derek

Hahaha!  Sometimes we need to revisit the code to see new things or look at things in a new light from a different perspective.  That's why I love programming so much, never stops to dazzle me how you can do the same thing over and over in many different ways each time.  This is awesome Derek, thanks as alwyas for your insight and excellent guidance.  Appreciate it!


Cheers!