locked
How do I use buttons correctly? RRS feed

  • Question

  • Ok, I know this is a pretty sad question, but still.

     

    How would the coding for a button that actually WORKS look like?

    On the actual studio editor, when you add a button and go under its events and hit 'click', it has a box for you to type in what to do when the event 'click' is raised.I don't know what to put in that box.

    I've tried things like:

    dialog1_load

    load dialog1

    load_dialog1

    click = load_dialog1

    click = load dialog1

     

    Yea, I'm pretty clueless.I can get most other things to work, but not buttons.Fail...


    Saturday, November 5, 2011 3:54 PM

Answers

  • On the actual studio editor, when you add a button and go under its events and hit 'click', it has a box for you to type in what to do when the event 'click' is raised.I don't know what to put in that box.

    Well neither do we, because we don't know what you are trying to do.

    Guessing from the examples you quote you seem to be trying to show some sort of dialog box so try something like:

       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Using OFD As New OpenFileDialog
             If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
                ' do something
             End If
          End Using
       End Sub
    
    

    • Proposed as answer by Sygrien Saturday, November 5, 2011 6:01 PM
    • Marked as answer by ChromeFusion44 Friday, November 11, 2011 11:26 PM
    Saturday, November 5, 2011 4:00 PM
  • It looks like the OP is accessing the 'events' window for the button object, and can understand the confusion. I don't think I've ever used the event property list...

    This list allows you to assign methods, that have the correct signature, to events for the specific object. You wouldn't use it to 'create' event methods.

    The easiest way to create event methods with the correct signature is to select the object (button in this case) from the left hand drop down list in the code window for the form, then select the specific event that you want to code from the right hand drop down list. This will create the method, with the correct signature and attach the object handler to that method (adds the 'handles' clause).

    Most objects have a default event. Double-clicking the object in the designer will automatically add - if it doesn't exist - the correct method, or go to that default method with the attached handler. The default event for a button is the click event.


    Stephen J Whiteley
    Tuesday, November 8, 2011 1:49 PM

All replies

  • On the actual studio editor, when you add a button and go under its events and hit 'click', it has a box for you to type in what to do when the event 'click' is raised.I don't know what to put in that box.

    Well neither do we, because we don't know what you are trying to do.

    Guessing from the examples you quote you seem to be trying to show some sort of dialog box so try something like:

       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Using OFD As New OpenFileDialog
             If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
                ' do something
             End If
          End Using
       End Sub
    
    

    • Proposed as answer by Sygrien Saturday, November 5, 2011 6:01 PM
    • Marked as answer by ChromeFusion44 Friday, November 11, 2011 11:26 PM
    Saturday, November 5, 2011 4:00 PM
  • Dave gave you the answer you need(double click you button to get the sub prepared for you by vb studio), but if you want my opinion, you really need to start watching some vb tutorials on youtube.

    Start by creating some basic projects like a calculator.


    TsopTsop
    Sunday, November 6, 2011 9:51 AM
  • It looks like the OP is accessing the 'events' window for the button object, and can understand the confusion. I don't think I've ever used the event property list...

    This list allows you to assign methods, that have the correct signature, to events for the specific object. You wouldn't use it to 'create' event methods.

    The easiest way to create event methods with the correct signature is to select the object (button in this case) from the left hand drop down list in the code window for the form, then select the specific event that you want to code from the right hand drop down list. This will create the method, with the correct signature and attach the object handler to that method (adds the 'handles' clause).

    Most objects have a default event. Double-clicking the object in the designer will automatically add - if it doesn't exist - the correct method, or go to that default method with the attached handler. The default event for a button is the click event.


    Stephen J Whiteley
    Tuesday, November 8, 2011 1:49 PM