Dynamically create buttons

Dynamically create buttons

Postby ctoas » Tue Mar 10, 2015 6:59 pm

Friends Good afternoon.

I need to dynamically create buttons, each button has a color defined by state, when clicked the button will change its state and therefore change their color.
How do?

Code: Select all  Expand view

        DO WHILE nSUITE <= 30
       
            VERIFICASTATUS(SUITES->STATUS,nCORFONTE,nCORFUNDO,cNOMESTATUS)
           
            @ nLIN, nCOL BTNBMP oBtn PROMPT cNOMESTATUS + CRLF +  CRLF + SUITES->NUMERO + CRLF + ALLTRIM(SUITES->NOME) + CRLF + CRLF + "PAP 1010" + CRLF + CRLF + DTOC(DATE()) + CRLF + TIME() ;
                        SIZE 58, 83 TOP NOBORDER FONT wfonte_STATUS ACTION MSGINFO(TRATASUITE(xSUITE))
                               
            oBtn:SetColor(nCORFONTE , nCORFUNDO)
        
        nSUITE ++
        nCOL += 60
        xSUITE ++
        
        IF nCOL == 601
            nLIN += 85
            nCOL := 01
        ENDIF
                
        SUITES->(DBSKIP())
        IF SUITES->(EOF())
            EXIT
            ENDIF
        ENDDO
 
Christiano Augusto Silveira
christiano.silveira@gmail.com

MaxxTech Soluções em TI
http://www.maxxtech.com.br
User avatar
ctoas
 
Posts: 115
Joined: Wed Oct 26, 2005 2:38 pm
Location: São Paulo - Brasil

Re: Dynamically create buttons

Postby ukoenig » Wed Mar 11, 2015 12:02 am

Christiano,

a sample :

Changes the 1. color and use oBtn[1]:Refresh()

nBColorF1 = 1. color
nBColorB1 = 2. color
nBGradPos1 = Gradient-pos

on Focus-color

nBColorF2 = 1. color
nBColorB2 = 2. color
nBGradPos2 = Gradient-pos

4 same colors = plain color NO gradient
define the colors from any function and use oBtn[1]:Refresh()

BITMAP shows the selected color nBColorF1 :

REDEFINE BITMAP oBMP[1] FILENAME NIL OF oDlg5 ;
ID 110 PIXEL ADJUST BORDER
oBMP[1]:cTooltip := "1. Color"
oBMP[1]:bPainted := { |hDC| BMP_COLOR( oBmp[1], hDC, nBColorF1 ) }


REDEFINE BTNBMP oBtn[1] OF oDlg5 ;
ID 120 PIXEL 2007 ;
NOBORDER ;
PROMPT "&1. Button-" + CRLF + "color" ;
FILENAME c_Pfad1 + "Paint1.Bmp" ;
ACTION ( nBColorF1 := ChooseColor(), oBmp[1]:Refresh(), oBtn[1]:Refresh() ) ;
FONT oFontSys ;
LEFT

oBtn[1]:bClrGrad := { | lMouseOver | If( ! lMouseOver,;
{ { nBGradPos1, nBColorF1, nBColorB1 }, ;
{ nBGradPos1, nBColorB1, nBColorF1 } }, ;
{ { nBGradPos2, nBColorF2, nBColorB2 }, ;
{ nBGradPos2, nBColorB2, nBColorF2 } } ) }

oBtn[1]:lTransparent := .t.
oBtn[1]:cToolTip = { "1. Btn-color" + CRLF + "Color","Color-Selection", 1, CLR_BLACK, 14089979 }
oBtn[1]:SetColor( 0, )

//------------- BMP-Brush shows the selected color -----------

FUNCTION BMP_COLOR( oBitmap, hDC, nColor )
LOCAL aRect := GETCLIENTRECT( oBitmap:hWnd )
LOCAL oBrush

DEFINE BRUSH oBrush COLOR nColor
FillRect( oBitmap:hDC, aRect, oBrush:hBrush )
oBrush:End()

RETURN( NIL )
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 90 guests