lrstndm Posted November 26, 2012 Posted November 26, 2012 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
PhoenixXL Posted November 26, 2012 Posted November 26, 2012 (edited) why not expandcollapse popup; 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 November 26, 2012 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.
lrstndm Posted November 26, 2012 Author Posted November 26, 2012 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
lrstndm Posted November 26, 2012 Author Posted November 26, 2012 I edit the code myself and it does what i want:) I used the GUICtrlCreateGraphic method. Thanks for the code
mihaibr Posted November 26, 2012 Posted November 26, 2012 you can do this using labels too $Form1 = GUICreate("Form1", 600, 400) $Label1 = GUICtrlCreateLabel("", 0, 0, 300, 400) GUICtrlSetBkColor(-1, 0x00FF00) $Label2 = GUICtrlCreateLabel("", 300, 0, 300, 400) GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3;$GUI_EVENT_CLOSE Exit EndSwitch Sleep(10) WEnd
4Eyes Posted November 27, 2012 Posted November 27, 2012 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now