GUI GetSet Prop Example Colour

From Sputnik Wiki
Jump to: navigation, search
Change colour of controls

Description

This example demonstrates how to change the Background and Foreground(Usuaully text) on buttons and windows.

Remarks

Colour values are R G B example 0xFF0000; Is RED 0x00FF00; Is GREEN 0x0000FF; Is BLUE

You can change the colours on just about every single control.

Example

// Create the MDI GUI
$GUI = GUICreate("Window", "GUI", 640, 480);
// Show the MDI GUI
GUILoad( $GUI );
 
// Make tab
$obj_TAB = GUICreate("TabSheet", $GUI, 5, 15, 610,  370);
// Add pages
$TabPage1 = GUICreate("TabPage", $obj_TAB, "Testy Tab1");
$TabPage2 = GUICreate("TabPage", $obj_TAB, "Testy Tab2");
$TabPage3 = GUICreate("TabPage", $obj_TAB, "Testy Tab3");
// Add buttons
$T1_Button1 = GUICreate("Button", $TabPage1, "My Button Tab1", 8, 8);
$T2_Button1 = GUICreate("Button", $TabPage2, "My Button Tab2", 8, 48);
$T3_Button1 = GUICreate("Button", $TabPage3, "My Button Tab3", 48, 38);
 
// Change the main window to Yellow
GUISetProp($GUI, "BackColor", 0xFFFF00); // Make it Yellow
println("Main Window BackColour" . Hex(GUIGetProp($GUI, "BackColor"))); // Print the colour
 
// Change the button background colours
GUISetProp($T1_Button1, "BackColor", 0xFF0000); // Make it Red
GUISetProp($T2_Button1, "BackColor", 0x0000FF); // Make it Blue
GUISetProp($T3_Button1, "BackColor", 0x00FF00); // Make it Green
// Get the hex of the colours so we could use it somewhere else
$HexB1 = Hex(GUIGetProp($T1_Button1, "BackColor"));
$HexB2 = Hex(GUIGetProp($T2_Button1, "BackColor"));
$HexB3 = Hex(GUIGetProp($T3_Button1, "BackColor"));
// Print the hex
println("Button 1 BackColour $HexB1");
println("Button 2 BackColour $HexB2");
println("Button 3 BackColour $HexB2");
 
// Change the button foreground (Text) colours
GUISetProp($T1_Button1, "ForeColor", 0x00FF00); // Make it Green
GUISetProp($T2_Button1, "ForeColor", 0xFF0000); // Make it Red
GUISetProp($T3_Button1, "ForeColor", 0x0000FF); // Make it Blue
// Get the hex of the colours so we could use it somewhere else
$HexB1 = Hex(GUIGetProp($T1_Button1, "ForeColor"));
$HexB2 = Hex(GUIGetProp($T2_Button1, "ForeColor"));
$HexB3 = Hex(GUIGetProp($T3_Button1, "ForeColor"));
// Print the hex
println("Button 1 ForeColour $HexB1");
println("Button 2 ForeColour $HexB2");
println("Button 3 ForeColour $HexB2");
 
// Keep the GUI running as long as long as the window is open
While ( GUIStatus( $GUI ) ) DoEvents( );

In this example we enter colours using their NAME instead of the Hex value to do this we use the Colour() command

// Create the MDI GUI
$GUI = GUICreate("Window", "GUI", 640, 480);
// Show the MDI GUI
GUILoad( $GUI );
 
// Make tab
$obj_TAB = GUICreate("TabSheet", $GUI, 5, 15, 610,  370);
// Add pages
$TabPage1 = GUICreate("TabPage", $obj_TAB, "Testy Tab1");
$TabPage2 = GUICreate("TabPage", $obj_TAB, "Testy Tab2");
$TabPage3 = GUICreate("TabPage", $obj_TAB, "Testy Tab3");
// Add buttons
$T1_Button1 = GUICreate("Button", $TabPage1, "My Button Tab1", 8, 8);
$T2_Button1 = GUICreate("Button", $TabPage2, "My Button Tab2", 8, 48);
$T3_Button1 = GUICreate("Button", $TabPage3, "My Button Tab3", 48, 38);
 
// Change the main window to Yellow
GUISetProp($GUI, "BackColor", Colour("Pink")); // Make it Pink
println("Main Window BackColour" . Hex(GUIGetProp($GUI, "BackColor"))); // Print the colour
 
// Change the button background colours
GUISetProp($T1_Button1, "BackColor", Colour("Red")); // Make it Red
GUISetProp($T2_Button1, "BackColor", Colour("Blue")); // Make it Blue
GUISetProp($T3_Button1, "BackColor", Colour("Green")); // Make it Green
// Get the hex of the colours so we could use it somewhere else
$HexB1 = Hex(GUIGetProp($T1_Button1, "BackColor"));
$HexB2 = Hex(GUIGetProp($T2_Button1, "BackColor"));
$HexB3 = Hex(GUIGetProp($T3_Button1, "BackColor"));
// Print the hex
println("Button 1 BackColour $HexB1");
println("Button 2 BackColour $HexB2");
println("Button 3 BackColour $HexB2");
 
// Change the button foreground (Text) colours
GUISetProp($T1_Button1, "ForeColor", Colour("Green")); // Make it Green
GUISetProp($T2_Button1, "ForeColor", Colour("Blue")); // Make it Red
GUISetProp($T3_Button1, "ForeColor", Colour("Red")); // Make it Blue
// Get the hex of the colours so we could use it somewhere else
$HexB1 = Hex(GUIGetProp($T1_Button1, "ForeColor"));
$HexB2 = Hex(GUIGetProp($T2_Button1, "ForeColor"));
$HexB3 = Hex(GUIGetProp($T3_Button1, "ForeColor"));
// Print the hex
println("Button 1 ForeColour $HexB1");
println("Button 2 ForeColour $HexB2");
println("Button 3 ForeColour $HexB2");
 
// Keep the GUI running as long as long as the window is open
While ( GUIStatus( $GUI ) ) DoEvents( );
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox