Results 1 to 6 of 6

Thread: Determine if an OK button is clicked

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question Determine if an OK button is clicked

    Quick question. Will anyone show me how to determine if a button is clicked or not in a form? I want to determine if an OK button is clicked or not.

    Thanks!

    ljCharlie

  2. #2
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    When you double click on the control in the design view it will open up the command button's click event.

    VB Code:
    1. Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
    2.         MsgBox("Ok button pressed")
    3. End Sub
    If wishes were fishes we'd all cast nets.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    Thanks for the response but here's what I want. Perhaps I should be more precise.

    I have two forms, form1 and form2. In form2 I have two buttons, btnCancel and btnOK. In form1, I want to determine if form2.btnOK is clicked or form2.btnCancel is clicked.

    ljCharlie

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    On form2 set btnOk as the AcceptButton and btnCancel as the CancelButton of the form. Then in their click event set the DialogResult to the proper value (ok/cancel) and close the form. Then when you show the form use ShowDialog instead of Show and it will return which button was pressed.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    Thanks for the help. How do I set the btnOK to AcceptButton and btnCancel to CancelButton?

    ljCharlie

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    AcceptButton and CancelButton are properties of the form, set them there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width