Recent

Author Topic: Button with colored background and wordwrap  (Read 9215 times)

Roosters

  • New Member
  • *
  • Posts: 16
Button with colored background and wordwrap
« on: January 01, 2012, 10:02:33 am »
This is for Windows.

I've searched, modified delphi code, used other controls, but try as I might I'm unable to find a button that has a working color property AND wordwrap.

I modified the standard TButton and gave it a wordwrap feature, this works great.

I understand that if I wish to use TButton as a starting point I have to use a customdraw routine, I have no idea how to implement this.

Can anyone point me in the right direction, better still some working code ?


digeo

  • Jr. Member
  • **
  • Posts: 54
    • Digeotek
Re: Button with colored background and wordwrap
« Reply #1 on: January 01, 2012, 11:31:14 am »
Have you taken a look at the BGRA Graphics and Controls Library. They have pretty cool button with gradient or just plain colour. I created an editor that you can download from my site to check possibilities. Because its lazarus, it should also run on al OS's.

Check following threads:
http://forum.lazarus.freepascal.org/index.php?topic=12411.0
http://forum.lazarus.freepascal.org/index.php?topic=15634.0

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Button with colored background and wordwrap
« Reply #2 on: January 01, 2012, 11:37:49 am »
I understand that if I wish to use TButton as a starting point I have to use a customdraw routine, I have no idea how to implement this.

Can anyone point me in the right direction, better still some working code ?

Try TCDButton from the Lazarus Custom Drawn Controls, which is a part of Lazarus:

http://wiki.lazarus.freepascal.org/Lazarus_Custom_Drawn_Controls

It has the color property and it works in all platforms. Patches are welcome for adding wordwrap.
« Last Edit: January 01, 2012, 11:44:31 am by felipemdc »

Roosters

  • New Member
  • *
  • Posts: 16
Re: Button with colored background and wordwrap
« Reply #3 on: January 01, 2012, 12:32:02 pm »
Thanks for the replies :-

 digeo :- I tried BGRA but it didn't have wordwrap property, I couldn't  get wordwrap to work with this.


felipemdc :- I also tried adding a wordwrap property to TCDButton, again it didn't work (like it does in TButton) .

I even inherited a new button from TCDButton, added wordwrap and that crashed lazarus.

Would you like to see the code I used to add wordwrap to TButton ?


felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Button with colored background and wordwrap
« Reply #4 on: January 01, 2012, 01:04:17 pm »
felipemdc :- I also tried adding a wordwrap property to TCDButton, again it didn't work (like it does in TButton) .
I even inherited a new button from TCDButton, added wordwrap and that crashed lazarus.
Would you like to see the code I used to add wordwrap to TButton ?

Yes, please send a patch. And I will already tell you the correct way to do this:

1> Add a WordWrap property in TCDButton
2> Add a WordWrap field in TCDButtonStateEx
3> Add synchronizing both values in TCDButton.PrepareStateEx
4> Handle this value in customdrawn_common.pas in DrawButton, check where it draws the text with ExtTextOut and use LCLIntf.DrawText instead (only when WordWrap=True) with correct values. You also need to change the button AutoSize calculation in GetPreferredSize in the same file

SONFEDAI

  • Jr. Member
  • **
  • Posts: 55
Re: Button with colored background and wordwrap
« Reply #5 on: January 01, 2012, 08:14:31 pm »
Where is the download package?

I Can't find
I'm using
   Lazarus: 0.9.3.1
   Date: 2011-11-05
   FPC: 2.5.1
   SVN Ver.: 29060

SONFEDAI

  • Jr. Member
  • **
  • Posts: 55
Re: Button with colored background and wordwrap
« Reply #6 on: January 01, 2012, 08:29:37 pm »
Sorry  %)

I'm found now
I'm using
   Lazarus: 0.9.3.1
   Date: 2011-11-05
   FPC: 2.5.1
   SVN Ver.: 29060

Roosters

  • New Member
  • *
  • Posts: 16
Re: Button with colored background and wordwrap
« Reply #7 on: January 05, 2012, 09:02:03 am »
Hi, sorry for the late reply, I was called away unexpectedly.

In the private section of Tbutton.pas i place the following

 FWordWrap : Boolean;
 procedure SetWordWrap(AValue: Boolean); 


In "published" I place this

property WordWrap: Boolean read fWordWrap write SetWordWrap default FALSE;

And finally after implementation I place the following procedure

procedure TButton1.SetWordWrap(AValue: Boolean);
begin
   if fWordWrap <> AValue then
  begin
    fWordWrap := AValue;
    recreateWnd(Self);
  end;
end; 


This works great for the standard Tbutton.

Thanks and once again apologies for not replying sooner after you were so helpfu

 

TinyPortal © 2005-2018