Changing bitmap on TBtnBmp at runtime

Changing bitmap on TBtnBmp at runtime

Postby reinaldocrespo » Sat Sep 21, 2013 10:22 pm

Hi,

Ok, how about changing the bitmap on a TbnBmp object at runtime?

Here is my code, but it isn't changing the bitmap.

Code: Select all  Expand view

...
   REDEFINE BUTTONBMP ::oBalance BITMAP "dotGreen" ID 501 OF ::oDlg TEXTRIGHT ;
               PROMPT oSelf:cDebt UPDATE
...
      ::oBalance:SetText( ::cDebt )
      ::oBalance:LoadBitMaps( IIF( nDebt > 0, "DotRed", "DotGray" ) )
      ::oBalance:Refresh()
 


Ideas?

Thank you,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Changing bitmap on TBtnBmp at runtime

Postby Marcelo Via Giglio » Sun Sep 22, 2013 12:06 am

Hola Reinaldo,

I don't know if this is the best solution, but I think work

Code: Select all  Expand view

....
::oBalance:hBitmap := LoadBitmap( GetResources(), IIF( nDebt > 0, "DotRed", "DotGray"  ) )
::oBalance:refresh()
...


saludos

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Changing bitmap on TBtnBmp at runtime

Postby Marcelo Via Giglio » Sun Sep 22, 2013 1:21 am

Reinaldo,

viendo el código fuente, creo que lo que está mal de tu código es tan solo una "S",

cambia

::oBalance:LoadBitMaps( IIF( nDebt > 0, "DotRed", "DotGray" ) )

por

::oBalance:LoadBitMap( IIF( nDebt > 0, "DotRed", "DotGray" ) )

saludos

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Changing bitmap on TBtnBmp at runtime

Postby Daniel Garcia-Gil » Sun Sep 22, 2013 1:42 am

Marcelo Via Giglio wrote:Reinaldo,

viendo el código fuente, creo que lo que está mal de tu código es tan solo una "S",

cambia

::oBalance:LoadBitMaps( IIF( nDebt > 0, "DotRed", "DotGray" ) )

por

::oBalance:LoadBitMap( IIF( nDebt > 0, "DotRed", "DotGray" ) )

saludos

Marcelo


Hello

it's a wrong way, because we need release the bitmap handle first,

Reinaldo you're using correct way, your code should be work fine

Marcelo Via Giglio wrote:::oBalance:LoadBitMap( IIF( nDebt > 0, "DotRed", "DotGray" ) )
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Changing bitmap on TBtnBmp at runtime

Postby nageswaragunupudi » Sun Sep 22, 2013 2:16 am

reinaldocrespo wrote:Hi,

Ok, how about changing the bitmap on a TbnBmp object at runtime?

Here is my code, but it isn't changing the bitmap.

Code: Select all  Expand view

...
   REDEFINE BUTTONBMP ::oBalance BITMAP "dotGreen" ID 501 OF ::oDlg TEXTRIGHT ;
               PROMPT oSelf:cDebt UPDATE
...
      ::oBalance:SetText( ::cDebt )
      ::oBalance:LoadBitMaps( IIF( nDebt > 0, "DotRed", "DotGray" ) )
      ::oBalance:Refresh()
 


Ideas?

Thank you,


Reinaldo.


This is TButtonBmp object and not TBtnBmp (FWH own class) object.
Should be :LoadBitmap(...) not :LoadBitmaps(...)
Method LoadBitmap() releases previous bitmap handle.
LoadBitmap accepts single parameter.

Here is a working sample to showing switching bitmap, text and alignment

Code: Select all  Expand view
function ButtnBmpChange()

   local oDlg, oFont, oBtn

   USE CUSTOMER NEW ALIAS CUST

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 200,140 PIXEL FONT oFont

   @ 10,10 BUTTONBMP oBtn PROMPT "Go Right" BITMAP "c:\fwh\bitmaps\right1.bmp" ;
      TEXTLEFT SIZE 80,20 PIXEL OF oDlg

   @ 40,10 BUTTONBMP PROMPT "Change" SIZE 80,20 PIXEL OF oDlg ;
      ACTION If( "left" $ oBtn:cBitmap, ;
         ( oBtn:LoadBitmap( "c:\fwh\bitmaps\right1.bmp" ), ;
           oBtn:SetText( "Go Right" ), ;
           oBtn:cPosText := "TEXTLEFT", oBtn:Refresh() ), ;
         ( oBtn:LoadBitmap( "c:\fwh\bitmaps\left1.bmp" ), ;
           oBtn:SetText( "Go Left" ), ;
           oBtn:cPosText := "TEXTRIGHT", oBtn:Refresh() ) ;
         )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Changing bitmap on TBtnBmp at runtime

Postby Rick Lipkin » Sun Sep 22, 2013 4:11 pm

To All

This code worked for me ..

Rick Lipkin

Code: Select all  Expand view

DO CASE
CASE lISGOALS = .T.            // found a goals record
     oBtn4:SetColor( "G/W*" )
     oBtn4:LoadBitmaps("OK", "DOK", "DOK" )
     oBTN4:ReFresh()
     SysReFresh()
OTHERWISE
     oBtn4:SetColor( "R+/W*" )
     oBtn4:LoadBitmaps("POWER", "DPOWER", "DPOWER" )
     oBtn4:ReFresh()
     SysReFresh()
ENDCASE
 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Changing bitmap on TBtnBmp at runtime

Postby nageswaragunupudi » Sun Sep 22, 2013 4:19 pm

Mr Rick

Though the caption says TBtnBmp actually the control is not TBtnBmp but TButtonBmp, if we see Mr. Reinaldo's code posted first.
Code: Select all  Expand view
  REDEFINE BUTTONBMP ::oBalance BITMAP "dotGreen" ID 501 OF ::oDlg TEXTRIGHT ;
 

The control is clearly TButtonBmp which is inherited from TButton and is basically a Windows Control.

TButtonBmp does not have Method LoadBitmaps( .... ) but only Method LoadBitmap() with a single parameter.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Changing bitmap on TBtnBmp at runtime

Postby reinaldocrespo » Sun Sep 22, 2013 4:51 pm

Everyone (Marcelo, Rao, Rick, Daniel) - Thank you very much.

Before posting the question, I had tried :loadbitmaps() as well as loadbitmap(), refresh(), GetResources(), and a few others. I had followed TButtonBmp source code and still could not figure out why it wasn't working until I realized that this piece of code was never executing do to a preexisting if condition that prevented program flow from executing it. I felt really stupid :-( LoadBitMap() followed by a refresh() works as expected. Thank you all VERY MUCH for your help.

Best regards,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 93 guests