# Casing Buttons

## Recommended Posts

hello everyone I need some urgent help I need to create a function that is based on buttons, that is setting data to Edits depending on the levels selected on the combobox, now I am able to use the buttons from the main guy where the function is only 1, but I need the same button to do different things depending of whats selected on the combobox thanks in advance for your help

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 229, 295, 192, 124)$Combo1 = GUICtrlCreateCombo("Combo1", 8, 8, 169, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData($Combo1, "|Item 1|Item 2|Item 3")$Button1 = GUICtrlCreateButton("Button1", 8, 40, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 88, 40, 75, 25)$Edit1 = GUICtrlCreateEdit("", 0, 80, 193, 177)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg() Switch$nMsg
Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd here is like an idea of flow of what im looking for if GUICtrlRead($combo1) = "Item 1" Then $Button1 sets edit1 data to yes and$button2 sets edit1 data to no
if GUICtrlRead($combo1) = "Item 2" Then$Button1 sets edit1 data to yes2 and $button2 sets edit1 data to no2 if GUICtrlRead($combo1) = "Item 3" Then $Button1 sets edit1 data to yes3 and$button2 sets edit1 data to no3

Edited by Melba23

##### Share on other sites

SerLanceloth,

Something like this should be what you want:

#include <GUIConstantsEx.au3>

Local $sButton1_Data = "",$sButton2_Data = ""

$Form1 = GUICreate("Form1", 229, 295, 192, 124)$Combo1 = GUICtrlCreateCombo("", 8, 8, 169, 25) ; The required styles are the defaults
GUICtrlSetData($Combo1, "|Item 1|Item 2|Item 3")$Button1 = GUICtrlCreateButton("Button1", 8, 40, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 88, 40, 75, 25)$Edit1 = GUICtrlCreateEdit("", 0, 80, 193, 177)

GUISetState(@SW_SHOW)

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE Exit Case$Combo1
Switch GUICtrlRead($Combo1) Case "Item 1"$sButton1_Data = "yes1"
$sButton2_Data = "no1" Case "Item 2"$sButton1_Data = "yes2"
$sButton2_Data = "no2" Case "Item 3"$sButton1_Data = "yes3"
$sButton2_Data = "no3" EndSwitch Case$Button1
GUICtrlSetData($Edit1,$sButton1_Data)
Case $Button2 GUICtrlSetData($Edit1, $sButton2_Data) EndSwitch WEnd And when you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columns ChooseFileFolder ---- Single and multiple selections from specified path treeview listing Date_Time_Convert -- Easily convert date/time formats, including the language used ExtMsgBox --------- A highly customisable replacement for MsgBox GUIExtender -------- Extend and retract multiple sections within a GUI GUIFrame ---------- Subdivide GUIs into many adjustable frames GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView Marquee ----------- Scrolling tickertape GUIs NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes Notify ------------- Small notifications on the edge of the display Scrollbars ----------Automatically sized scrollbars with a single command StringSize ---------- Automatically size controls to fit text Toast -------------- Small GUIs which pop out of the notification area #### Share this post ##### Link to post ##### Share on other sites thanks melba you awesome, im trying to save and hit on next line, i manage for it to save it by adding the 1 after the coma at the end, but how can i make it write on next line? #include <GUIConstantsEx.au3> Local$sButton1_Data = "", $sButton2_Data = ""$Form1 = GUICreate("Form1", 229, 295, 192, 124)

$Combo1 = GUICtrlCreateCombo("", 8, 8, 169, 25) ; The required styles are the defaults GUICtrlSetData($Combo1, "|Item 1|Item 2|Item 3")
$Button1 = GUICtrlCreateButton("Button1", 8, 40, 75, 25)$Button2 = GUICtrlCreateButton("Button2", 88, 40, 75, 25)
$Edit1 = GUICtrlCreateEdit("", 0, 80, 193, 177) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case$GUI_EVENT_CLOSE
Exit
Case $Combo1 Switch GUICtrlRead($Combo1)
Case "Item 1"
$sButton1_Data = "yes1"$sButton2_Data = "no1"
Case "Item 2"
$sButton1_Data = "yes2"$sButton2_Data = "no2"
Case "Item 3"
$sButton1_Data = "yes3"$sButton2_Data = "no3"
EndSwitch

Case $Button1 GUICtrlSetData($Edit1, $sButton1_Data,1) Case$Button2
GUICtrlSetData($Edit1,$sButton2_Data,1)
EndSwitch

WEnd

##### Share on other sites

SerLanceloth,

What do you think might make the edit control move down a line? What would you press if you were using a keyboard?

GUICtrlSetData($Edit1,$sButton1_Data & @CRLF, 1) ; Add an EOL

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

## Create an account

Register a new account

• ### Similar Content

• By DannyJ
Hello Forum,
I have one special Combo-box [with BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE) ] and if I press one button I want to change the Combo-box's background color, and after I press Button B I want to change it to the basic settings and it not works. I wanna do this with one combo-box. I have already tried several methods and I tried GUICtrlComboSetColors that I have found on this forum. (But this methods works perfectly with Cobo boxes that don't have BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE).
Here is the example code
#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= ;$CBS_DROPDOWNLIST ;$GUI_SS_DEFAULT_COMBO $Form1 = GUICreate("Form1", 504, 249, 252, 227)$Combo1 = GUICtrlCreateCombo("", 136, 24, 193, 25,BitOR($CBS_DROPDOWNLIST,$GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; I want to change this special combo's background color if I press button 1$Button1 = GUICtrlCreateButton("Button1", 112, 96, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 264, 96, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1," " & "|" & "apple" & "|" & "banana" & "|" & "cherry" ," ") While 1 $nMsg = GUIGetMsg() Switch$nMsg Case $GUI_EVENT_CLOSE Exit Case$Button1 GUICtrlSetBkColor($Combo1,0x0078D7) Case$Button2 ;Makes the original bc color GUICtrlSetBkColor(Combo1,0xFFFFFF) EndSwitch WEnd Thanks you in advance your help • Good morning, I am trying to align a two-line text in a button so that it would be centered in the button but can't succeed to do it for the vertical part. Can someone tell me what I do wrong ? Here is my code:btn3 = GUICtrlCreateButton("Execute " & @LF & " file 1", 100, 65, 60, 50, _ BitOr($BS_CENTER,$BS_BOTTOM,$BS_MULTILINE)) and here is the resulting layout I get in my window. I tried to follow the help, made a lot of different parameter combinations (here it's $BS_BOTTOM, but I tried $BS_VCENTER and $BS_TOP), still get the same result : vertical alignement is a no go for me.
Can someone help ?
TIA
Gilles

• By Pike
Hey Everyone, I haven't been here in a while and recently picked up my old project. Still an FNG!
To the point: I want to be able to push the button and either play an mp3, open a file, or open an exe program (all with the same button). The problem is that I don't know how to code for that at "case 1"
Case 1
Local $sRead = IniRead("config.ini", "Config", "One", "Default") SoundPlay($sRead, @HotKeyPressed)                                                                     <-------------------------------
Run($sRead, @HotKeyPressed) <------------------------------- This 'Run' doesn't work even by itself! See code below for layout. If you need more information I will attach more code or answer any questions. Any help is greatly appreciated. Much Respect, Pike Func _HandleButton()$iClickCount += 1 $iTimer = TimerInit() AdlibRegister("CheckButtonPress",$CheckTime) EndFunc Func CheckButtonPress() If TimerDiff($iTimer) <$CheckTime Or $iTimer = 0 Then Return Switch$iClickCount Case 1 Local $sRead = IniRead("config.ini", "Config", "One", "Default") SoundPlay($sRead, @HotKeyPressed) Run($sRead, @HotKeyPressed) Case 2 MsgBox(0, "INFORMATION:", "Choose the file you want designated to this button") Local$sFileOpenDialog = FileOpenDialog(0, @ScriptDir & "\", "All (*.*)", $FD_FILEMUSTEXIST +$FD_MULTISELECT) If @error Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") EndIf Local$sFileName = InputBox("INFORMATION:", "Please Name Your File?" & @CRLF _ & @CRLF _ & "6 Characters or Less", "") IniWrite(@ScriptDir & "\config.ini", "Config", "One", $sFileOpenDialog) IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne",$sFileName) EndSwitch $iClickCount = 0 AdlibUnRegister() EndFunc • By misioooo Hi! I am writing some GUI and i need to use images as buttons, but with text on them (text is from INI file). Part with button looks like this:$ankieta1 = GUICtrlCreateButton($txtAnk1, 100,350,765,164) GUICtrlSetFont(-1, 22, 800, -1, "Arial") ;GUICtrlSetColor(-1,0xffffff)$hImageBtn_1 = _GUIImageList_Create(765, 164) _GUIImageList_AddBitmap($hImageBtn_1, "c:\path\to\ankieta_clean.bmp") _GUICtrlButton_SetImageList($ankieta1, $hImageBtn_1, 4) GUICtrlSetOnEvent(-1, "On_Ankieta1") The problem - if i uncomment GUICtrlSetColor, color of text changes, but button is just plain gray (no image). How i can change text color not touching image on a button here? • By Reher Hi so i ran into a Problem i didn't expect to get stuck on. It sounds simple (and probably is) but i can't seem to get it to work So i created a Combobox and filled it with some things from an array which worked fine.$combobox = GUICtrlCreateCombo($list[0], 160, 200, 265, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GuiCtrlSetData($list, "|" & _ArrayToString($list,Default,1),$list[2]) GUICtrlSetFont(-1, 9, 400, 0, "Arial") Now i want to change the style of the combobox from $CBS_DROPDOWN to$CBS_DROPDOWNLIST via a checkbox.
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 160, 96, 105, 25) Case$Checkbox1 If GUICtrlRead($Checkbox1) =$GUI_CHECKED Then Call ("Read_only") Else Call ("Edit") Endif Func Read_only() GUICtrlSetStyle ($Combobox1,something to change it to$CBS_DROPDOWNLIST) EndFunc Func Edit() GUICtrlSetStyle ($Combobox1,something to change it to$CBS_DROPDOW) EndFunc I tried using $CBS_DROPDOWN and$CBS_DROPDOWNLIST but it simply does nothing.
I also tried \$ES_READONLY which kinda worked, it changed the combobox so i couldn't change the input via dropdown anymore but i could still type in it via keyboard (which i dont want).
It's essential that its Editable but once the checkbox is checked the combobox becomes readonly so you can't type in it anymore but you can still choose between the items in the list. (It does not have to save your current input if you write something in it and then check the Checkbox it would be best if it would simpy jump back to the first item in the list)
Im sure this is a simple thing but after long google search im tired of my stupidity can someone give me a push in the right direction?
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...