FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Changing bitmap on TBtnBmp at runtime
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Changing bitmap on TBtnBmp at runtime
Posted: 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 (fw): Select all Collapse
...
聽 聽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.
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Changing bitmap on TBtnBmp at runtime
Posted: Sun Sep 22, 2013 12:06 AM
Hola Reinaldo,

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

Code (fw): Select all Collapse
 
....
::oBalance:hBitmap := LoadBitmap( GetResources(), IIF( nDebt > 0, "DotRed", "DotGray" 聽) )
::oBalance:refresh()
...


saludos

Marcelo
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: Changing bitmap on TBtnBmp at runtime
Posted: Sun Sep 22, 2013 01: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

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Changing bitmap on TBtnBmp at runtime
Posted: Sun Sep 22, 2013 01: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

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

por

::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:::LoadBitMap( IIF( nDebt > 0, "DotRed", "DotGray" ) )
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Changing bitmap on TBtnBmp at runtime
Posted: Sun Sep 22, 2013 02: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 (fw): Select all Collapse
...
聽 聽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 (fw): Select all Collapse
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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Changing bitmap on TBtnBmp at runtime
Posted: Sun Sep 22, 2013 04:11 PM
To All

This code worked for me ..

Rick Lipkin

Code (fw): Select all Collapse
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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Changing bitmap on TBtnBmp at runtime
Posted: Sun Sep 22, 2013 04: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 (fw): Select all Collapse
   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
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Changing bitmap on TBtnBmp at runtime
Posted: Sun Sep 22, 2013 04: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.

Continue the discussion