locked
Button Events RRS feed

  • Question

  • Hi everyone,

    I am finding it hard to figure out how to use the button click event. I can display a button on the screen and use the event to show a messagebox however it does the same with any button I click.

    Can someone write be a basic example on 2 buttons on the screen and both displaying different messageboxes this would be great.

    Thanks,

    Kirkkaf.

    Saturday, July 10, 2010 4:33 PM

Answers

  • Kirkkaf, simple 2 button example

    button1 = Controls.AddButton("Button 1",50,50)
    button2 = Controls.AddButton("Button 2",50,100)
    Controls.ButtonClicked = OnButtonClicked

    Sub OnButtonClicked
      button = Controls.LastClickedButton
      If (button = button1) Then
        GraphicsWindow.ShowMessage("Button 1 pressed", "Information")
      ElseIf (button = button2) Then
        GraphicsWindow.ShowMessage("Button 2 pressed", "Information")
      EndIf
    EndSub

    • Marked as answer by Kirkkaf Saturday, July 10, 2010 8:35 PM
    Saturday, July 10, 2010 4:41 PM

All replies

  • Kirkkaf, simple 2 button example

    button1 = Controls.AddButton("Button 1",50,50)
    button2 = Controls.AddButton("Button 2",50,100)
    Controls.ButtonClicked = OnButtonClicked

    Sub OnButtonClicked
      button = Controls.LastClickedButton
      If (button = button1) Then
        GraphicsWindow.ShowMessage("Button 1 pressed", "Information")
      ElseIf (button = button2) Then
        GraphicsWindow.ShowMessage("Button 2 pressed", "Information")
      EndIf
    EndSub

    • Marked as answer by Kirkkaf Saturday, July 10, 2010 8:35 PM
    Saturday, July 10, 2010 4:41 PM
  • Thanks for your help this has made it alot clearer for me now.

    Kirkkaf.

    Saturday, July 10, 2010 8:35 PM
  • Just what I was looking for! Thanks!
    Wednesday, July 1, 2015 2:02 PM