Jump to content

Gui Font & Color


Kohr
 Share

Recommended Posts

Here is something I put together today because I got tired of setting the color and/or font over and over manually in code to see how it would look in the autoit gui. I believe I put all of the controls in this that are affected by changing the fonts. Any feedback would be welcome.

Also if anyone knows how to get the default font and color that is used (when you do not use GUISetBkColor or GUISetFont) I would appreciate it. I could not figure out that part so I just made a workaround.

Kohr

#include <GUIConstants.au3>
#include <Misc.au3>
#include <Array.au3>
Global $btn, $chkFont, $label2, $label3, $btnColor, $chkColor, $lblColor
Global $main
Global $aFont[8]
Global $defaultFont, $defaultColor
Global $color
$defaultFont = 1
$defaultColor = 1
fGui()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $btn
            If GUICtrlRead($chkFont) = $GUI_CHECKED Then
                $defaultFont = 1
            Else
                $defaultFont = 0
            EndIf
            $aFont = _ChooseFont (GUICtrlRead($label2), GUICtrlRead($label3))
            GUIDelete()
            fGui()
        Case $btnColor
            If GUICtrlRead($chkColor) = $GUI_CHECKED Then
                $defaultColor = 1
            Else
                $defaultColor = 0
            EndIf
            $color = _ChooseColor (2, GUICtrlRead($lblColor))
            ConsoleWrite($color & @CRLF)
            GUIDelete()
            fGui()
    EndSwitch
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
    
Func fGui() 
; GUI
    $main = GUICreate ("GUI Font & Color", 600, 400)

; --- Font Add ---
    $btn = GUICtrlCreateButton ( "Font", 10, 10, 60, 20)
    $chkFont = GuiCtrlCreateCheckbox("DefaultFont", 80, 10, 80, 20)
    GuiCtrlCreateLabel("attributes", 10, 50, 50, 20)
    $label1 = GuiCtrlCreateLabel($aFont[1], 70, 50, 80, 20)
    GuiCtrlCreateLabel("fontname", 10, 70, 50, 20)
    $label2 = GuiCtrlCreateLabel($aFont[2], 70, 70, 80, 20)
    GuiCtrlCreateLabel("size", 10, 90, 50, 20)
    $label3 = GuiCtrlCreateLabel($aFont[3], 70, 90, 80, 20)
    GuiCtrlCreateLabel("weight", 10, 110, 50, 20)
    $label4 = GuiCtrlCreateLabel($aFont[4], 70, 110, 80, 20)
    GuiCtrlCreateLabel("colorref", 10, 130, 50, 20)
    $label5 = GuiCtrlCreateLabel($aFont[5], 70, 130, 80, 20)
    GuiCtrlCreateLabel("hex BGR", 10, 150, 50, 20)
    $label6 = GuiCtrlCreateLabel($aFont[6], 70, 150, 80, 20)
    GuiCtrlCreateLabel("hex RGB", 10, 170, 50, 20)
    $label7 = GuiCtrlCreateLabel($aFont[7], 70, 170, 80, 20)
    If $defaultFont = 1 Then
        GuiCtrlSetState($chkFont, $GUI_CHECKED)
        GUICtrlSetData($label1, "Default")
        GUICtrlSetData($label2, "Default")
        GUICtrlSetData($label3, "Default")
        GUICtrlSetData($label4, "Default")
        GUICtrlSetData($label5, "Default")
        GUICtrlSetData($label6, "Default")
        GUICtrlSetData($label7, "Default")
    Else
        GUISetFont ($aFont[3], $aFont[4], $aFont[1], $aFont[2])
    EndIf
    
; --- color ---
    $btnColor = GUICtrlCreateButton ( "Color", 10, 190, 60, 20)
    $chkColor = GuiCtrlCreateCheckbox("DefaultColor", 80, 190, 80, 20)
    GuiCtrlCreateLabel("hex RGB", 10, 220, 50, 20)
    $lblColor = GuiCtrlCreateLabel($color, 70, 220, 80, 20)
    If $defaultColor = 1 Then
        GuiCtrlSetState($chkColor, $GUI_CHECKED)
        GUISetBkColor (-1)
        GUICtrlSetData($lblColor, "-1")
    Else
        GUISetBkColor ($color)
    EndIf

    $g1 = GUICtrlCreateGraphic ( 190, 1, 10, 400)
    GUICtrlSetGraphic ( $g1, $GUI_GR_LINE, 1, 400)


; TAB
    GuiCtrlCreateTab(300, 10, 150, 70)
    GuiCtrlCreateTabItem("One")
    GuiCtrlCreateTabItem("Two")
    GuiCtrlCreateTabItem("Three")
    GuiCtrlCreateTabItem("")
; COMBO
    GuiCtrlCreatecombo("Item 1", 460, 10, 120, 100)
    GUICtrlSetData(-1,"Item 2|Item 3")
; EDIT
    GuiCtrlCreateEdit(@CRLF & "  Sample Edit Control", 210, 100, 150, 70)
; LIST
    GuiCtrlCreateList("", 210, 190, 160, 160)
    GuiCtrlSetData(-1, "a.Sample|b.List|c.Control|d.Here", "b.List")
; LIST VIEW
    $listView = GuiCtrlCreateListView("Sample|ListView|", 410, 190, 160, 150)
    GuiCtrlCreateListViewItem("A|One", $listView)
    GuiCtrlCreateListViewItem("B|Two", $listView)
    GuiCtrlCreateListViewItem("C|Three", $listView)
; GROUP WITH RADIO BUTTONS
    GuiCtrlCreateGroup("Sample Group", 370, 95, 90, 80)
    GuiCtrlCreateRadio("Radio One", 375, 120, 70)
    GuiCtrlSetState(-1, $GUI_CHECKED)
    GuiCtrlCreateRadio("Radio Two", 375, 150, 70)
    GUICtrlCreateGroup ("",-99,-99,1,1) ;close group
; UPDOWN
    GuiCtrlCreateInput("42", 210, 70, 40, 20)
    GuiCtrlCreateUpDown(-1)
; LABEL
    GuiCtrlCreateLabel("Label", 490, 165, 40, 40)
; INPUT
    GuiCtrlCreateInput("Sample Input Box", 460, 50, 120, 20)
; DATE
    GuiCtrlCreateDate("", 210, 350, 230, 20)
; BUTTON
    GuiCtrlCreateButton("Sample Button", 490, 100, 100, 30)
; CHECKBOX
    GuiCtrlCreateCheckbox("Checkbox", 490, 140, 80, 20)
    GuiCtrlSetState(-1, $GUI_CHECKED)

    GUISetState ()
EndFunc
Link to comment
Share on other sites

gafrost,

I have seen that one and it is much more advanced. I was just trying to make something simple that changed the font/colors and the whole gui is affected. This way I can see what it looks like on the entire gui. I sometimes pick a font/color that doesn't look as good once it is used.

I was also considering adding the same ability to ListView controls because I would find myself picking a color/font combination and then not liking it.

The last idea I had for this was to turn it into something that I can easily add as a setup option for any gui made so users of a script could set the color/font to their own preference. That would be more eye candy for users of scripts I make at work so it is just a future idea.

Kohr

Link to comment
Share on other sites

gafrost,

I have seen that one and it is much more advanced. I was just trying to make something simple that changed the font/colors and the whole gui is affected. This way I can see what it looks like on the entire gui. I sometimes pick a font/color that doesn't look as good once it is used.

I was also considering adding the same ability to ListView controls because I would find myself picking a color/font combination and then not liking it.

The last idea I had for this was to turn it into something that I can easily add as a setup option for any gui made so users of a script could set the color/font to their own preference. That would be more eye candy for users of scripts I make at work so it is just a future idea.

Kohr

Understand, I did something similar with Code Snippet, can set the colors for the tree view

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

hi,

tis code of mine for colors works for me.

#include <GuiConstants.au3>
#include <File.au3>
#include <Misc.au3>

Local $color

$test = GUICreate("MyGUI", 392, 316, -1, -1)
$Pic_1 = GUICtrlCreatePic("", 30, 30, 170, 150)
$Button_1 = GUICtrlCreateButton("Browse for Photo", 230, 70, 150, 40)
$Button_2 = GUICtrlCreateButton("Browse for Bkgrd", 230, 140, 150, 40)
$Group_1 = GUICtrlCreateGroup("My Photo", 28, 15, 175, 170)
$combo = GUICtrlCreateCombo("", 230, 25, 150, 40)
$Colour = GUICtrlCreateButton("Browse for Colors", 230, 240, 150, 40)
$file = "D:\Test.txt"
GUICtrlSetData($combo, "Select Bkgrd Color|Yellow|Blue|Green|Red", "Select Bkgrd Color")
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            $var = FileOpenDialog("Choose", "", "Images (*.jpg)")
            If @error Then
            ; Do Nothing
            Else
                FileWrite($file, "")
                $var = StringReplace($var, "|", @CRLF)
                GUICtrlSetImage($Pic_1, $var)
                $Pic_1 = GUICtrlCreatePic($var, 30, 30, 170, 150)
                _FileWriteToLine($file, 1, $var, 1)
            EndIf
        Case $msg = $Button_2
            $var2 = FileOpenDialog("Choose", "", "Images (*.jpg;*.bmp;*.gif)|")
            If @error Then
            ; Do Nothing
            Else
                GUIDelete($test)
                $test = GUICreate("MyGUI", 392, 316, -1, -1)
                $GPic = GUICtrlCreatePic($var2, -1, -1, 392, 316)
                GUICtrlSetState($GPic, $GUI_DISABLE)
                $GPic = GUICtrlCreatePic($var2, 0, 0, 400, 315)
                GUICtrlSetState($GPic, $GUI_DISABLE)
                $Group_1 = GUICtrlCreateGroup("My Photo", 28, 15, 175, 170)
                $Button_1 = GUICtrlCreateButton("Browse for Photo", 230, 70, 150, 40)
                $Button_2 = GUICtrlCreateButton("Browse for Bkgrd", 230, 140, 150, 40)
                $combo = GUICtrlCreateCombo("", 230, 25, 150, 40)
                GUICtrlSetData($combo, "Select Bkgrd Color|Yellow|Blue|Green|Red", "Select Bkgrd Color")
                $read = FileReadLine($file, 1)
                $Pic_1 = GUICtrlCreatePic($read, 30, 30, 170, 150)
                GUISetState()
            EndIf
        Case $msg = $combo
            If GUICtrlRead($combo) = "Yellow" Then GUISetBkColor(0xFFFF99)
            If GUICtrlRead($combo) = "Red" Then GUISetBkColor(0xFF3333)
            If GUICtrlRead($combo) = "Green" Then GUISetBkColor(0x66FF99)
            If GUICtrlRead($combo) = "Blue" Then GUISetBkColor(0x9999FF)
        Case $msg = $Colour
            $color = _ChooseColor (0)
            GUISetBkColor($color)
        Case Else
        ;
    EndSelect
WEnd
FileDelete($file)
Exit

mouse not found....scroll any mouse to continue.

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...