Jump to content

Working with script generated buttons


98700
 Share

Recommended Posts

Hello everyone, I'm having trouble finding a way to use the buttons i generate from user input. This is the code i am using to create my buttons. The two arguments for the function are read from two input boxes.

Func GenerateButtons($Height,$Width)
$Form2 = GUICreate("",$Width*25,$Height*25)
Dim $Buttons[$Height][$Width]
GUISetState(@SW_SHOW)
$h = 0
$w = 0
While 1
$Buttons[$h][$w] = GUICtrlCreateButton("0",$w*25,$h*25,25,25)
If Not($w=$Width-1) Then
$w+=1
Else
$w=0
If ($h=$Height-1) Then
ExitLoop
Else
$h+=1
EndIf
EndIf
WEnd
EndFunc

Okay so what i want to do is add one to the number on a button when it is pressed, but I am having trouble figuring out how to do that. If you need any more info let me know! Thanks.

Link to comment
Share on other sites

Maybe this is what u basically want

Local $Form2 = GUICreate("",220,100)
Local $nButton=GUICtrlCreateButton(0,10,10,200,80)
Local $iMsg
GUISetState()
While $iMsg<>-3
$iMsg=GUIGetMsg()
Switch $iMsg
Case $nButton
GUICtrlSetData($nButton,Number(GUICtrlRead($nButton))+1)
EndSwitch
WEnd
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.

Link to comment
Share on other sites

Well that would work but the number of buttons varies. When the script first starts it has two input boxes and a button. the numbers you type into the boxes are the amount of button rows and collumns. Each button has a variable ($Buttons[$h][$w]). the $h is the y position and the $w is the x position. So basically i just can't figure out how to react when one of them is pressed.

Link to comment
Share on other sites

Give the full script I dont see any inputboxes in your code

Each button has a variable ($Buttons[$h][$w]). the $h is the y position and the $w is the x position. So basically i just can't figure out how to react when one of them is pressed.

Its odd if the button is in 10=x and 20=y

then you have made an array of $Buttons[20][10]

its just not required

Give the full script.

Debugging is required

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.

Link to comment
Share on other sites

#include
#include
#include
#include
#include

#Region ### Variables
$Height = 0
$Width = 0
$GenButtons = False
#EndRegion ###

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("", 157, 114)
$HeightInput = GUICtrlCreateInput("0", 32, 32, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Label1 = GUICtrlCreateLabel("Dimesions?", 16, 8, 127, 17)
$Label2 = GUICtrlCreateLabel("x", 72, 32, 12, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$WidthInput = GUICtrlCreateInput("0", 88, 32, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Label3 = GUICtrlCreateLabel("Height", 32, 56, 35, 17)
$Label4 = GUICtrlCreateLabel("Width", 88, 56, 32, 17)
$Button1 = GUICtrlCreateButton("Generate", 40, 80, 73, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
HotKeySet("{ESC}","Terminate")

Main()

Func Main()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $HeightInput
$Height = GUICtrlRead($HeightInput)
Case $WidthInput
$Width = GUICtrlRead($WidthInput)
Case $Button1
GenerateButtons($Height,$Width)
EndSwitch
WEnd
EndFunc

Func Terminate()
Exit
EndFunc

Func GenerateButtons($Height,$Width)
$Form2 = GUICreate("",$Width*25,$Height*25)
Global $Buttons[$Height][$Width]
Dim $ButtonN[100]
GUISetState(@SW_SHOW)
$h = 0
$w = 0
Global $ButtonCount = 0
While 1
$Buttons[$h][$w] = GUICtrlCreateButton("0",$w*25,$h*25,25,25)
$ButtonN[((($h*$Width)+$w)+10)] = GUICtrlGetHandle(-1)
ConsoleWrite($ButtonCount & "= "&$ButtonN[((($h*$Width)+$w)+10)]&" ")
$ButtonCount +=1
If Not($w=$Width-1) Then
$w+=1
Else
$w=0
If ($h=$Height-1) Then
ExitLoop
Else
$h+=1
EndIf
EndIf
WEnd

Sleep(1000) ;<<<<<<<<<<<<<<<<This last part was just for testing to see the buttons id's
$nMsg = GUIGetMsg()
If($nMsg = $GUI_EVENT_PRIMARYUP) Then
ConsoleWrite($nMsg&" ")
ConsoleWrite($Buttons[0][0])
EndIf
EndFunc

That is the full code.

Link to comment
Share on other sites

Hope so this is Enough

It took me a fair amount of time :)

GenerateButtons(5,2)
GenerateButtons(20,10)
GenerateButtons(3,1)
GenerateButtons(6,2)
GenerateButtons(90,2)


Func GenerateButtons($sNumber,$sLine=1,$Width=70,$Height=50,$sButtonSpacing=10,$hBorderSpacing=20)
If $sLine>=$sNumber Then $sLine=$sNumber
Local $sMaxButton=Ceiling($sNumber/$sLine)
Local $Form2 = GUICreate("Phoenix XL _Testing.au3", _
($sMaxButton*$Width)+(2*$hBorderSpacing)+(($sMaxButton-1)*$sButtonSpacing), _
($sLine*$Height)+(2*$hBorderSpacing)+(($sLine-1)*$sButtonSpacing))
Global $Buttons[$sNumber+1]
Local $h = $hBorderSpacing
Local $w = $hBorderSpacing
For $i=1 To $sNumber
$Buttons[$i]=GUICtrlCreateButton(0,$w,$h,$Width,$Height)
GUICtrlSetTip(-1,'Button Number: '&$i,'Information',1,3)
If IsMultiple($i,$sMaxButton) Then
$h+=$Height+$sButtonSpacing
$w = $hBorderSpacing
Else
$w+=$Width+$sButtonSpacing
EndIf
Next
GUISetState()
Local $nMsg
While 1
$nMsg=GUIGetMsg()
Switch $nMsg
Case -3
Return GUIDelete($Form2)
Case $Buttons[1] To $Buttons[$sNumber]
GUICtrlSetData($nMsg,Number(GUICtrlRead($nMsg))+1)
EndSwitch
WEnd
EndFunc

Func IsMultiple($nNumber,$sFactor)
If IsInt($nNumber/$sFactor) Then Return 1
Return 0
EndFunc
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.

Link to comment
Share on other sites

It checks for the button number with respect to the column index

if two columns are there then

the height should change after every 2nd button for this the button number should be a multiple of 2

Hope this helps

Regards

Phoenix XL

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.

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