Jump to content
Sign in to follow this  
lrstndm

Set 2 different background colors in 1 GUI

Recommended Posts

Hi all,

Is it possible to set 2 different background colors in 1 GUI?

Or can you else set the background color of a Picture element?

regards,

lrstndm

Share this post


Link to post
Share on other sites

why not :)

; gradient 2 - Graphic
#include <WindowsConstants.au3> ;Newer AutoIt versions
#include <GuiConstants.au3> ;Older AutoIt include has WM_ constants
#include <Color.au3>
#include <WinAPI.au3>

Global Const $G_VERTICAL = 1
Global Const $G_HORIZONTAL = 2

CreateWindow()

Do
Until GUIGetMsg() = -3

Func CreateWindow()
Local $iColTop = 0x808080
Local $iColBtm = 0xFFFFFF
Local $GUI_Width = 300
Local $GUI_Height = 400
GUICreate("Gradient Demo", $GUI_Width, $GUI_Height, (@DesktopWidth - $GUI_Width) / 2, (@DesktopHeight - $GUI_Height) / 2, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS)
GUICtrlCreateGradient($iColTop, $iColBtm,0, 0,$GUI_Width,$GUI_Height, $G_VERTICAL)
GUICtrlCreateLabel('Hey There',100,10,100,15,1)
GUICtrlSetBkColor(-1,-2) ;Transparent
GUICtrlCreateEdit("First line" & @CRLF, 176, 32, 121, 97)
GUISetState()
EndFunc   ;==>CreateWindow

Func GUICtrlCreateGradient($nStartColor, $nEndColor, $nX, $nY,$nWidth = 255, $nHeight = 20,$n_type = 1)
;Gary Frost
;[url="http://www.autoitscript.com/forum/topic/30907-color-gradients-easy/page__view__findpost__p__221361"http://www.autoitscript.com/forum/topic/30907-color-gradients-easy/page__view__findpost__p__221361[/url]

Local $colorR = _ColorGetRed($nStartColor)
Local $colorG = _ColorGetGreen($nStartColor)
Local $colorB = _ColorGetBlue($nStartColor)
Local $nStepR, $nStepG, $nStepB, $sColor
GUICtrlCreateGraphic($nX, $nY, $nWidth, $nHeight)
Select
Case $n_type = $G_VERTICAL
$nStepR = (_ColorGetRed($nEndColor) - $colorR) / $nWidth
$nStepG = (_ColorGetGreen($nEndColor) - $colorG) / $nWidth
$nStepB = (_ColorGetBlue($nEndColor) - $colorB) / $nWidth
For $i = 0 To $nWidth
$sColor = "0x" & StringFormat("%02X%02X%02X", $colorR + $nStepR * $i, $colorG + $nStepG * $i, $colorB + $nStepB * $i)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xFFFFFF)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $i, 0)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $i, $nHeight)
Next
Case $n_type = $G_HORIZONTAL
$nStepR = (_ColorGetRed($nEndColor) - $colorR) / $nHeight
$nStepG = (_ColorGetGreen($nEndColor) - $colorG) / $nHeight
$nStepB = (_ColorGetBlue($nEndColor) - $colorB) / $nHeight
For $i = 0 To $nHeight
$sColor = "0x" & StringFormat("%02X%02X%02X", $colorR + $nStepR * $i, $colorG + $nStepG * $i, $colorB + $nStepB * $i)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xFFFFFF)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $nWidth, $i)
Next
EndSelect
GUICtrlSetState(-1,128)
EndFunc   ;==>_GUICtrlCreateGradient

modify as per your needs

Its not my Code - from the FORUM

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Awesome code but not excatly what i wanted...

I want for example, the left side of the GUI a green color, and the right side of the GUI yellow.

Thanks in advance

Share this post


Link to post
Share on other sites

An easy method I've used before is to create a gradient or whatever graphic in paint (or whatever), then set it as the background in a label. Create whatever other controls over the top.

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...