Jump to content

Lable with color


Recommended Posts

Can someone help me out to get this part please?

As soon as I would Type '1' or '2' or '3' or '4' in the box, the respective Lable color should change to Green.

Say if I Type '1' then Step 1 lable should show as Step 1

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 388, 241, 750, 360)
$Step1 = GUICtrlCreateLabel("Step 1", 32, 40, 42, 20)
$Step2 = GUICtrlCreateLabel("Step 3", 216, 40, 42, 20)
$Step3 = GUICtrlCreateLabel("Step 2", 120, 40, 42, 20)
$Step4 = GUICtrlCreateLabel("Step 4", 312, 40, 42, 20)
$Input_Text = GUICtrlCreateInput("", 48, 104, 289, 24)
$OK = GUICtrlCreateButton("OK", 152, 176, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    $aInfo = GUIGetCursorInfo($Form1)
    If $aInfo[2] Then
        If $aInfo[4] = $Input_Text Then GUICtrlSetData($Input_Text, "")
    EndIf

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit


        Case $OK
            Select
                Case GUICtrlRead($Input_Text) = '1'
                $verify = MsgBox(68, "", "Do you want to proceed with Step 1?")
                    Select
                        Case $verify = '6'
                            Exit
                        Case $verify = '7'
                            ; Cancel Exit
                    EndSelect
                    Msgbox(0,"","step1")

                Case GUICtrlRead($Input_Text) = '2'
                    Msgbox(0,"","step2")

                Case GUICtrlRead($Input_Text) = '3'
                    Msgbox(0,"","step3")

                Case GUICtrlRead($Input_Text) = '4'
                    Msgbox(0,"","step4")
            EndSelect

    EndSwitch
WEnd

 

Link to comment
Share on other sites

You can start with this :

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 388, 241, 750, 360)
$Step1 = GUICtrlCreateLabel("Step 1", 32, 40, 42, 20)
$Step2 = GUICtrlCreateLabel("Step 2", 120, 40, 42, 20)
$Step3 = GUICtrlCreateLabel("Step 3", 216, 40, 42, 20)
$Step4 = GUICtrlCreateLabel("Step 4", 312, 40, 42, 20)
$Input_Text = GUICtrlCreateInput("", 48, 104, 289, 24)
$OK = GUICtrlCreateButton("OK", 152, 176, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

Local $oldVal, $oldControl

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
    EndSwitch
    
    $val = GUICtrlRead($Input_Text)
    If $val <> $oldVal Then
        
        Switch $val
            Case "1"
                $newControl = $Step1
            Case "2"
                $newControl = $Step2
            Case "3"
                $newControl = $Step3
            Case "4"
                $newControl = $Step4
            Case Else
                $newControl = 0
        EndSwitch
        
        GUICtrlSetBkColor($oldControl, $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetBkColor($newControl, 0x00ff00)

        $oldVal = $val
        $oldControl = $newControl
    EndIf
WEnd

You can also make your code lighter by using GUIRegisterMsg  + $WM_COMMAND + $EN_CHANGE

This following code is not really clean, but can show you this method (you should put your controls in an array to simplify the code)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 388, 241, 750, 360)
$Step1 = GUICtrlCreateLabel("Step 1", 32, 40, 42, 20)
$Step2 = GUICtrlCreateLabel("Step 2", 120, 40, 42, 20)
$Step3 = GUICtrlCreateLabel("Step 3", 216, 40, 42, 20)
$Step4 = GUICtrlCreateLabel("Step 4", 312, 40, 42, 20)
$Input_Text = GUICtrlCreateInput("", 48, 104, 289, 24)
$OK = GUICtrlCreateButton("OK", 152, 176, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

Local $oldControl

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
    EndSwitch
    

WEnd

Func _WM_COMMAND($hWnd, $imsg, $iwParam, $ilParam)
    Local $setHK = False
    $nNotifyCode = BitShift($iwParam, 16)
    $nID = BitAND($iwParam, 0x0000FFFF)

    
    Switch $nID
        Case $Input_Text
            Switch $nNotifyCode
                Case $EN_CHANGE
                    Switch GUICtrlRead($Input_Text)
                        Case "1"
                            $newControl = $Step1
                        Case "2"
                            $newControl = $Step2
                        Case "3"
                            $newControl = $Step3
                        Case "4"
                            $newControl = $Step3
                        Case Else
                            $newControl = 0
                    EndSwitch
                    
                    If $oldControl <> 0 Then GUICtrlSetBkColor($oldControl, $GUI_BKCOLOR_TRANSPARENT)
                    If $newControl <> 0 Then GUICtrlSetBkColor($newControl, 0x00ff00)
                    $oldControl = $newControl
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
   

EndFunc  ;==>My_WM_COMMAND

 

Edited by jguinch
Link to comment
Share on other sites

@ jguinch

Thank you for your help. I Like the 1st option. Though there is 2 issues here.

1. As soon as I select either 1, 2 or 3 the options color do change but then it does not wait for me to select OK button and starts the programs. I want the color to be changed when I type the numbers but wait for me to select OK to run the program.

2. In my actual code, I have given the last Case as if the numbers typed are not 1, 2 or 3 then it would throw me an error msgbox. But it doesn't happen here. I have made comment on the last Case for the way I had written in my actual code as

Case GUICtrlRead($$Input_Text) <> '1' Or GUICtrlRead($$Input_Text) <> '2' Or GUICtrlRead($$Input_Text) <> '3' Or GUICtrlRead($$Input_Text) <> '4'

;MsgBox(0, "", "Invalid input")   

 

Try running this...

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 388, 241, 750, 360)
$Step1 = GUICtrlCreateLabel("Step 1", 32, 40, 42, 20)
$Step2 = GUICtrlCreateLabel("Step 2", 120, 40, 42, 20)
$Step3 = GUICtrlCreateLabel("Step 3", 216, 40, 42, 20)
$Step4 = GUICtrlCreateLabel("Step 4", 312, 40, 42, 20)
$Input_Text = GUICtrlCreateInput("", 48, 104, 289, 24)
$OK = GUICtrlCreateButton("OK", 152, 176, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

Local $oldVal, $oldControl

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
    EndSwitch
    
    $val = GUICtrlRead($Input_Text)
    If $val <> $oldVal Then
        
        Switch $val
            Case "1"
                $newControl = $Step1
                MsgBox(0, "", "Invalid Step 1")
            Case "2"
                $newControl = $Step2
                MsgBox(0, "", "Invalid Step 2")
            Case "3"
                $newControl = $Step3
                MsgBox(0, "", "Invalid Step 3")
            Case "4"
                $newControl = $Step4
                MsgBox(0, "", "Invalid Step 4")
            Case Else
                $newControl = 0
            ;Case Not "1" or Not "2" or Not "3" or Not "4"
            ; MsgBox(0, "", "Invalid Input")
        EndSwitch
        
        GUICtrlSetBkColor($oldControl, $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetBkColor($newControl, 0x00ff00)

        $oldVal = $val
        $oldControl = $newControl
    EndIf
WEnd

 

Edited by sunshinesmile84
Link to comment
Share on other sites

I have made some changes here... When I type 1, 2, 3 or 4 it colors the lables. If no input then error. If anything else than 1,2,3 or 4 then another error. Everything is good.

The only thing I want is the msgbox to come up only when OK is pressed.

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 388, 241, 750, 360)
$Step1 = GUICtrlCreateLabel("Step 1", 32, 40, 42, 20)
$Step2 = GUICtrlCreateLabel("Step 2", 120, 40, 42, 20)
$Step3 = GUICtrlCreateLabel("Step 3", 216, 40, 42, 20)
$Step4 = GUICtrlCreateLabel("Step 4", 312, 40, 42, 20)
$Input_Text = GUICtrlCreateInput("", 48, 104, 289, 24)
$OK = GUICtrlCreateButton("OK", 152, 176, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

Local $oldVal, $oldControl, $newControl

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $OK
    EndSwitch

    $val = GUICtrlRead($Input_Text)
    If $val <> $oldVal Then

        Switch $val
            Case "1"
                $newControl = $Step1
                ;GUICtrlSetColor($oldControl, $GUI_BKCOLOR_TRANSPARENT)
                GUICtrlSetColor($newControl, $COLOR_GREEN)
                MsgBox(0, "", "Invalid Step 1")
                GUICtrlSetColor($newControl, $COLOR_BLACK)

            Case "2"
                $newControl = $Step2
                GUICtrlSetColor($newControl, $COLOR_GREEN)
                MsgBox(0, "", "Invalid Step 2")
                GUICtrlSetColor($newControl, $COLOR_BLACK)

            Case "3"
                $newControl = $Step3
                GUICtrlSetColor($newControl, $COLOR_GREEN)
                MsgBox(0, "", "Invalid Step 3")
                GUICtrlSetColor($newControl, $COLOR_BLACK)

            Case "4"
                $newControl = $Step4
                GUICtrlSetColor($newControl, $COLOR_GREEN)
                MsgBox(0, "", "Invalid Step 4")
                GUICtrlSetColor($newControl, $COLOR_BLACK)

            Case $val <> "1" Or $val <> "2" Or $val <> "3" Or $val <> "4"
                MsgBox(0, "", "Invalid Input")

            Case Else
                $val = ""
                MsgBox(0, "", "No Input")
        EndSwitch

        $oldVal = $val
        $oldControl = $newControl
    EndIf

WEnd

 

Link to comment
Share on other sites

So you MsgBox must be placed in the Case $OK statement.

Look at this ~horrible~ code :

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 388, 241, 750, 360)
$Step1 = GUICtrlCreateLabel("Step 1", 32, 40, 42, 20)
$Step2 = GUICtrlCreateLabel("Step 2", 120, 40, 42, 20)
$Step3 = GUICtrlCreateLabel("Step 3", 216, 40, 42, 20)
$Step4 = GUICtrlCreateLabel("Step 4", 312, 40, 42, 20)
$Input_Text = GUICtrlCreateInput("", 190, 104, 30, 24, $ES_NUMBER)
GUICtrlSetLimit(-1, 1, 1)
$OK = GUICtrlCreateButton("OK", 152, 176, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Local $oldVal, $oldControl, $newControl

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
            Switch $newControl
                Case ""
                    MsgBox(16, "", "No Input")
                Case Else
                    MsgBox(0, "", "Let's go for " & GUICtrlRead($newControl) )
            EndSwitch
    EndSwitch
    
    $val = GUICtrlRead($Input_Text)
    If $val <> $oldVal Then
        
        Switch $val
            Case "1"
                $newControl = $Step1
            Case "2"
                $newControl = $Step2
            Case "3"
                $newControl = $Step3
            Case "4"
                $newControl = $Step4
            Case ""
                $newControl = 0
            Case Else
                $aPos = WinGetPos(GUICtrlGetHandle($Input_Text))
                ToolTip ( "Invalid data", $aPos[0] + $aPos[2] / 2, $aPos[1] + $aPos[3] / 2 , "Invalid data", 3 , 1 )
                Sleep(1000)
                GUICtrlSetData($Input_Text, "")
                ToolTip("") 
        EndSwitch
        
        
        GUICtrlSetColor($oldControl, 0)
        GUICtrlSetColor($newControl, 0x00ff00)

        $oldVal = $val
        $oldControl = $newControl
    EndIf
WEnd

 

Link to comment
Share on other sites

It's doing the same thing... I get the Steps colored if enterred 1, 2, 3, 4 but it does not wait for the OK button to be pressed.

1. When you enter 1 it colors Step 1 lable. - Good

2. When you select OK, it displays message Step 1. - Good ; This is just for testing and not required.

3. When you select OK, Step1 function should run as per the msgbox I have given below. Same way with Step 2, and Step 3.

Try to put the below messagebox in your above code. It doesn't wait for OK button to be pressed.

 

Switch $val
            Case "1"
                $newControl = $Step1

msgbox(0, "", "Step1 Function should call")


            Case "2"
                $newControl = $Step2
            Case "3"
                $newControl = $Step3

Link to comment
Share on other sites

I had to change few things and it is working all good now.

There is just one last thing if you could help me with today.

When I enter 1 in the Input and press OK, it should run the Step1 Function. Now when the func starts as you can see I have given a confirmation screen. If it's Yes then it will display the msgbox (which means will perform the actions in Step 1). If NO then the confirmation screen will only close. Not the complete GUI... Now becuase I had to keep everything inside a function and outside the While > Wend, the CONTINUELOOP will give error.

Is there any other way to write the msgbox for confirmation for Yes / No so that Continue loop will not have to be written but it Yes/No will still work as it has to...

 

#include<process.au3>
#include <Date.au3>
#include <File.au3>
#include <IE.au3>
#include <Array.au3>
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ColorConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 388, 241, 750, 360)
$Step1 = GUICtrlCreateLabel("Step 1", 32, 40, 42, 20)
$Step2 = GUICtrlCreateLabel("Step 2", 120, 40, 42, 20)
$Step3 = GUICtrlCreateLabel("Step 3", 216, 40, 42, 20)
$Step4 = GUICtrlCreateLabel("Step 4", 312, 40, 42, 20)
$Input_Text = GUICtrlCreateInput("", 48, 104, 289, 24, $ES_NUMBER)
GUICtrlSetLimit(-1, 1, 1)
$OK = GUICtrlCreateButton("OK", 152, 176, 75, 25, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Local $oldVal, $oldControl, $newControl

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
            Switch $newControl
                Case ""
                    MsgBox(16, "Error", "No Input")
                Case $Step1
                    GUICtrlRead($newControl, Step1())
                Case $Step2
                    GUICtrlRead($newControl, Step2())
                Case $Step3
                    GUICtrlRead($newControl, Step3())
                Case $Step4
                    GUICtrlRead($newControl, Step4())
            EndSwitch
    EndSwitch

    $val = GUICtrlRead($Input_Text)
    If $val <> $oldVal Then

        Switch $val
            Case "1"
                $newControl = $Step1

            Case "2"
                $newControl = $Step2

            Case "3"
                $newControl = $Step3

            Case "4"
                $newControl = $Step4

            Case ""
                $newControl = 0
            Case Else
                $aPos = WinGetPos(GUICtrlGetHandle($Input_Text))
                ToolTip("Invalid data", $aPos[0] + $aPos[2] / 2, $aPos[1] + $aPos[3] / 2, "Invalid data", 3, 1)
                Sleep(1000)
                GUICtrlSetData($Input_Text, "")
                ToolTip("")
        EndSwitch


        GUICtrlSetColor($oldControl, 0)
        GUICtrlSetColor($newControl, 0x00ff00)

        $oldVal = $val
        $oldControl = $newControl
    EndIf
WEnd


Func Step1()
    $Confirm = MsgBox(68, "", "Continue?")
    Select
        Case $Confirm = $IDYES
            ; Cancel Exit
        Case $Confirm = $IDNO
            ContinueLoop
    EndSelect
    MsgBox(0, "", "Performing step 1")
EndFunc   ;==>Step1

Func Step2()
    MsgBox(0, "", "Performing step 2")
EndFunc   ;==>Step2

Func Step3()
    MsgBox(0, "", "Performing step 3")
EndFunc   ;==>Step3

Func Step4()
    MsgBox(0, "", "Performing step 4")
EndFunc   ;==>Step4

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...