Jump to content

Recommended Posts

I was wondering if there is a way to change the background color of a gui and refresh or redraw the gui without having to exit the script and run it again.

The following code is an example:

; Change Window Color.au3
#include <GUIConstants.au3>
#include <Misc.au3>
Dim $Menu_Window_Color

$Window_Color = 0xffffff; White

GUICreate( "Change Window Color", 400, 200, -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetBkColor( $Window_Color)
GUICtrlCreateLabel( "Right-Click to see Menu.", 100, 50, 200, 18)

_Create_Context_Menu(); Create Right-Click Menu
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $Menu_Window_Color Then _Change_Window_Color()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Exit

Func _Create_Context_Menu(); Create Right-Click Menu
    $Menu_Window = GUICtrlCreateContextMenu()
    $Menu_Window_Color = GUICtrlCreateMenuitem("Color", $Menu_Window)
EndFunc; --> _Create_Context_Menu

Func _Change_Window_Color(); Change Window Color
    $New_Window_Color = _ChooseColor( 2, $Window_Color, 2)
    MsgBox( 0, "$New_Window_Color", $New_Window_Color)
    $Window_Color = $New_Window_Color
; ******** I Want to Refresh or Redraw Window here to show New Window Color. ********
EndFunc; --> _Change_Window_Color

Thanks in advance for any help.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to post
Share on other sites
  • Moderators

Like this?

; Change Window Color.au3
#include <GUIConstants.au3>
#include <Misc.au3>
Dim $Menu_Window_Color

$Window_Color = 0xffffff; White

$Main = GUICreate( "Change Window Color", 400, 200, -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetBkColor( $Window_Color)
GUICtrlCreateLabel( "Right-Click to see Menu.", 100, 50, 200, 18)

_Create_Context_Menu(); Create Right-Click Menu
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $Menu_Window_Color Then 
        GUISetBkColor(_Change_Window_Color(), $Main)
    EndIf
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Exit

Func _Create_Context_Menu(); Create Right-Click Menu
    $Menu_Window = GUICtrlCreateContextMenu()
    $Menu_Window_Color = GUICtrlCreateMenuitem("Color", $Menu_Window)
EndFunc; --> _Create_Context_Menu

Func _Change_Window_Color(); Change Window Color
    $New_Window_Color = _ChooseColor( 2, $Window_Color, 2)
    MsgBox( 0, "$New_Window_Color", $New_Window_Color)
    $Window_Color = $New_Window_Color
    Return $Window_Color
; ******** I Want to Refresh or Redraw Window here to show New Window Color. ********
EndFunc; --> _Change_Window_Color

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to post
Share on other sites

Like this?

Yes SmOke_N,

Exactly like that. :D

Thank you sir!

taurus905

Edited: SmOke_N,

By editing those few lines, you showed me something so basic to AutoIt and programming in general.

I appreciate you taking the time. I will use this technique in the future to make my life easier.

Thank you for your quick response.

Edited by taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...