CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Option buttons

  1. #1
    Guest

    Option buttons

    I have two option buttons, I wish to toggle between them every time the space bar is hit how is this done ?



  2. #2
    Guest

    Re: Option buttons

    Capture the keyboard_event and if the ASCii value of the key pressed is equal to the value for space bar, enable/disable the appropriate button.


  3. #3
    Guest

    Re: Option buttons

    How do you capture a keyboard event ?


  4. #4
    Guest

    Re: Option buttons

    Don't know why I can't get this to work for the space bar (ascii value = 32), but it works just fine for the Enter key (ascii value = 13) and just about any other key BUT the spacebar.

    Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 And Option1.Value = True Then
    Option1.Value = Not Option1.Value
    Option2.Value = Not Option2.Value
    Else
    Option2.Value = Not Option2.Value
    Option1.Value = Not Option1.Value
    End If



  5. #5
    Join Date
    Apr 1999
    Location
    Brooklyn, NY USA
    Posts
    171

    Re: Option buttons

    First of all set KeyPreview property of form to true. Then use this code:

    private Sub Form_KeyDown(KeyCode as Integer, Shift as Integer)
    If KeyCode = 32 then KeyCode = 13
    If KeyCode = 13 then
    If Option1 then
    Option2 = Not Option2
    else
    Option1 = Not Option1
    End If
    End If
    End Sub



    Vlad


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

Featured