Jump to content

Deleting a button made from an array.


Recommended Posts

I had this problem a couple days back and brushed it off thinking it wouldn't come up again but I got bored and wanted to find out how to do this. I tried all kind of things (I tried _ArrayDelete()) just wondering if anyone knows how to do this, please help me.

$gui = GuiCreate("",215,300,-1,-1)
Opt("GUIOnEventMode",1)
GuiSetOnEvent(-3,"_Exit")
Local $button[11]
$y = 5
For $i = 1 To 10
    $button[$i] = GUICtrlCreateButton($i,5,$y,100,20)
    GUICtrlSetOnEvent($button[$i],"_Button")
    $y += 30
Next
$y = 5
Local $delete[11]
For $i = 1 To 10
$delete[$i] = GUICtrlCreateButton("Delete "&$i,110,$y,100,20)
GUICtrlSetOnEvent($delete[$i],"_Button_Delete")
    $y += 30
Next
$y = 0
GuiSetState()

While 1
Sleep(10)
Wend

Func _Exit()
Exit
EndFunc

Func _Button()
    $id = GUICtrlRead(@GUI_CtrlId,1)
    MsgBox(0,"Clicked","Button "&'"'&$id&'"'&" was clicked")
EndFunc

Func _Button_Delete()
    $id = GUICtrlRead(@gui_ctrlid,1)
    $string = StringRight($id,1)
    If $id = "Delete 10" Then
        $string = StringRight($id,2)
    EndIf
    MsgBox(0,"Clicked","Button "&'"'&$id&'"'&" was clicked"&@CRLF&"Its number is "&$string)
    ;-- What do I put here to delete the corresponding button?
EndFunc

 

Link to comment
Share on other sites

You could do this, but your going to have to make sure that each delete button matches to the corresponding button.

 

$gui = GUICreate("", 215, 300, -1, -1)
Opt("GUIOnEventMode", 1)
GUISetOnEvent(-3, "_Exit")
Local $button[11]
$y = 5
For $i = 1 To 10
    $button[$i] = GUICtrlCreateButton($i, 5, $y, 100, 20)
    GUICtrlSetOnEvent($button[$i], "_Button")
    $y += 30
Next
$y = 5
Local $delete[11]
For $i = 1 To 10
    $delete[$i] = GUICtrlCreateButton("Delete " & $i, 110, $y, 100, 20)
    GUICtrlSetOnEvent($delete[$i], "_Button_Delete")
    $y += 30
Next
$y = 0
GUISetState()

While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Button()
    $id = GUICtrlRead(@GUI_CtrlId, 1)
    MsgBox(0, "Clicked", "Button " & '"' & $id & '"' & " was clicked")
EndFunc   ;==>_Button

Func _Button_Delete()
    $id = GUICtrlRead(@GUI_CtrlId, 1)
    $string = StringRight($id, 1)
    If $id = "Delete 10" Then
        $string = StringRight($id, 2)
    EndIf
    MsgBox(0, "Clicked", "Button " & '"' & $id & '"' & " was clicked" & @CRLF & "Its number is " & $string)
    ;-- What do I put here to delete the corresponding button?

    GUICtrlDelete(@GUI_CtrlId - 10)

EndFunc   ;==>_Button_Delete

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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