PDA

View Full Version : progressbar with colour possible?



largo_winch
06-01-2013, 15:49
I have found an old example on my hd and try to add an progressbar in my second gui/dialog. I wanted to make a coloured progressbar (I didn't want to have a marquee!) and with "+" or "-" button I wanted to change the "level" of this colour. this example shows my status and there's missing the callback or function how to set these colour level. I only can add one point or substract it for the level, that' s not perfect. If anybody can help I am very glad to get help.

progressbar and set colour that's a feature in current thinbasic version?

the not perfect working example I add as attachment.

the code you can see in second post, "starwriter" doesn't like from time to time code tags for copying and pasting my code example ;)

bye, largo

largo_winch
06-01-2013, 16:03
' Empty GUI script created on 01-06-2013 12:59:05 by (thinAir)


Uses "console", "UI"


Begin Const
%ID_PROGRESS = 500
%ID_PROGRLBL
%ID_PROGRLBL2
%IDD_DIALOG1
%IDC_PROGRESSBAR1
%IDC_PROGRESSBAR2
%ID_ScrollBar1
%IDC_LABEL1
%IDC_BUTTON1
%IDC_BUTTON2
%IDC_TEXTBOX1
%IDC_BUTTON3
End Const


'--- good or better using %WM_INITDIALOG ? ----------
Function SetProgressBar(ByVal hDlg As Long, ByVal pPos As Long) As Long
Control Add ProgressBar hDlg, %IDC_PROGRESSBAR1, pPos,14,50,20,40
Control Set Color hDlg, %IDC_PROGRESSBAR1, Rgb(100, 255, 0), Rgb(0, 255, 0)
ProgressBar_SetMarquee hDlg, %IDC_PROGRESSBAR1, %TRUE, Rnd(50, 150)
Control Set Resize hDlg, %IDC_PROGRESSBAR1, 1, 1, 0, 0

Control Set Text hDlg, %IDC_LABEL1, Str$(pPos)+"%"
Control Set Text hDlg, %IDC_TEXTBOX1, Trim$(Str$(pPos))
End Function


'--------------------------
Function TBMain () As Long ' MAIN
'--------------------------
Local hDlg As DWord


Dialog Font "Comic Sans", 14
Dialog New 0, "simple start gui",-1,-1, 160, 80, %WS_CAPTION Or %WS_SYSMENU To hDlg
Dialog Set Color hDlg, -1, Rgb(200,180,220)


Control Add Label, hDlg, -1, "push start to show next dialog", 5, 65, 130, 10, %SS_CENTER
Control Set Color hDlg, -1, -1, Rgb(22,200,22)


Control Add Button, hDlg, %IDOK, "&Start", 18, 40, 50, 14
Control Add Button, hDlg, %IDCANCEL, "&Close", 72, 40, 50, 14


Dialog Show Modal hDlg Call MyMainDlgProc


End Function


'-- cb one -------------------------------------
CallBack Function MyMainDlgProc () As Long
Select Case CBMSG


Case %WM_COMMAND
Select Case CBCTL


Case %IDOK
If CBCTLMSG = %BN_CLICKED Then
ShowProgressGui CBHNDL
End If


Case %IDCANCEL
If CBCTLMSG = %BN_CLICKED Then
Dialog End CBHNDL
End If


End Select


End Select


End Function


Sub ShowProgressGui (ByVal hParent As Long)
Local hDlg As Long
Dialog New 0, "ProgressBar with Coloured Level (?)",-1,-1, 140, 200, _
%WS_POPUP Or _
%WS_VISIBLE Or _
%WS_CLIPCHILDREN Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_MINIMIZEBOX, _
0 To hDlg


Control Add ProgressBar, hDlg, %IDC_PROGRESSBAR1, "", 50, 15, 20, 100, _
%WS_CHILD Or %WS_VISIBLE Or %PBS_SMOOTH Or %PBS_VERTICAL
Control Set Color hDlg, %IDC_PROGRESSBAR1, -1, Rgb(222,192,192)
Control Add Label, hDlg, %IDC_LABEL1, "", 80, 60, 40, 10
Control Add Button, hDlg, %IDC_BUTTON1, "+", 10, 15, 25, 10
Control Add Button, hDlg, %IDC_BUTTON2, "-", 10, 105, 25, 10
Control Add Button, hDlg, %IDC_BUTTON3, "Accept", 50, 135, 70, 15
Control Add Textbox, hDlg, %IDC_TEXTBOX1,"", 10, 136, 25, 13, _
%ES_NUMBER Or %WS_TABSTOP Or %WS_BORDER Or %ES_LEFT, _
%WS_EX_CLIENTEDGE Or %WS_EX_LEFT


Dialog Show Modal hDlg, Call ShowBarProc
End Sub


'-- cb two -------------------------------------
CallBack Function ShowBarProc()
Local txty As String
Local pPos As Long, MaxSteps As Long
'pPos = 500

Select Case CBMSG
Case %WM_INITDIALOG
SetProgressBar(CBHNDL,pPos)

Control Add ProgressBar CBHNDL, %IDC_PROGRESSBAR1, pPos,14,50,20,40
ProgressBar_SetRange CBHNDL, %IDC_PROGRESSBAR1, 0, pPos
ProgressBar_SetStep CBHNDL, %IDC_PROGRESSBAR1, 1 '---Set automatic step increment
ProgressBar_SetPos CBHNDL, %IDC_PROGRESSBAR1, 0 '---Set current bar position

ProgressBar_SetMarquee CBHNDL, %IDC_PROGRESSBAR1, %TRUE, Rnd(50, 150)
Control Set Resize CBHNDL, %IDC_PROGRESSBAR1, 1, 1, 0, 0

Case %WM_COMMAND
Select Case CBCTL
Case %IDC_BUTTON1
MaxSteps = 500
ProgressBar_SetRange CBHNDL, %IDC_PROGRESSBAR1, 0, MaxSteps '---Set PB min and max values
ProgressBar_SetStep CBHNDL, %IDC_PROGRESSBAR1, 1 '---Set automatic step increment
ProgressBar_SetPos CBHNDL, %IDC_PROGRESSBAR1, 0 '---Set current bar position

If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
pPos=Min(pPos+1,100)
SetProgressBar(CBHNDL,pPos)
End If


Case %IDC_BUTTON2
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
pPos=Max(pPos-1,0)
SetProgressBar(CBHNDL,pPos)
End If


Case %IDC_BUTTON3
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %IDC_TEXTBOX1 To txty
pPos=Min(Val(txty),100)
SetProgressBar(CBHNDL,pPos)
End If


End Select
End Select
End Function

ErosOlmi
06-01-2013, 20:13
All thinBasic UI controls are themed so their colors are dependent on theme.
To be able to change colors to a progress bar control, untheme it using Control UnTheme (http://www.thinbasic.com/public/products/thinBasic/help/html/index.html?control_untheme.htm) function just after creating it.

Like this:

Control UnTheme CBHNDL, %IDC_PROGRESSBAR1
Than use:

Control Set Color CBHNDL, %IDC_PROGRESSBAR1

Example:

Uses "UI"
Begin ControlID
%IDC_PROGRESSBAR1
%IDC_LABEL1
%IDC_BUTTON_PLUS
%IDC_BUTTON_MINUS
%IDC_TEXTBOX1
%IDC_BUTTON3
End ControlID

Function TBMain() As Long
Local hDlg As Long

Dialog New 0, "ProgressBar with Coloured Level (?)",-1,-1, 220, 200, _
%WS_POPUP Or _
%WS_VISIBLE Or _
%WS_CLIPCHILDREN Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_MINIMIZEBOX, _
0 To hDlg


Dialog Show Modal hDlg, Call ShowBarProc
End Function


'-- cb two -------------------------------------
CallBack Function ShowBarProc()
Local lPos As Long

Select Case CBMSG
Case %WM_INITDIALOG
Control Add ProgressBar CBHNDL, %IDC_PROGRESSBAR1, "", 10, 50, 200, 40
ProgressBar_SetRange CBHNDL, %IDC_PROGRESSBAR1, 0, 25
ProgressBar_SetPos CBHNDL, %IDC_PROGRESSBAR1, 0
Control Set Color CBHNDL, %IDC_PROGRESSBAR1, -1, Rgb(255, 0, 0)


Control Add Button, CBHNDL, %IDC_BUTTON_MINUS , "-", 10, 15, 25, 15
Control Add Button, CBHNDL, %IDC_BUTTON_PLUS , "+", 185, 15, 25, 15


'---!!!!!!! Here the trick to change color
Control UnTheme CBHNDL, %IDC_PROGRESSBAR1

Case %WM_COMMAND
Select Case CBCTL

Case %IDC_BUTTON_PLUS
lPos = ProgressBar_GetPos(CBHNDL, %IDC_PROGRESSBAR1)
If lPos < 25 Then
Incr lPos
Else
lPos = 0
End If
ProgressBar_SetPos CBHNDL, %IDC_PROGRESSBAR1, lPos


Control Set Color CBHNDL, %IDC_PROGRESSBAR1, Rgb(lPos * 10, lPos * 10, 255), Rgb(255, 0, 0)

Case %IDC_BUTTON_MINUS
lPos = ProgressBar_GetPos(CBHNDL, %IDC_PROGRESSBAR1)
If lPos < 1 Then
lPos = 25
Else
Decr lPos
End If
ProgressBar_SetPos CBHNDL, %IDC_PROGRESSBAR1, lPos



End Select
End Select

End Function

Ciao
Eros

largo_winch
09-01-2013, 11:05
thank you for your help eros! the "untheme" command I haven't realized until you sent your post here. good idea! but if that's possible you can create for any further thinbasic update this "progressbar_setColor" command too? :) bye, largo