Results 1 to 16 of 16

Thread: command button question

  1. #1

    Thread Starter
    Junior Member CapFlea03's Avatar
    Join Date
    Apr 2004
    Location
    Dallas, Texas
    Posts
    29

    command button question

    is it possible to check command buttons for the focus and change the color of the button with the focus?

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Question

    Simply said:
    VB Code:
    1. Private Sub Command1_GotFocus()
    2.     Command1.BackColor = RGB(255, 0, 0)
    3. End Sub

    Note that you have to set Command1.Style to 1 in the Form editor (you can't access it at runtime that easy).

  3. #3

    Thread Starter
    Junior Member CapFlea03's Avatar
    Join Date
    Apr 2004
    Location
    Dallas, Texas
    Posts
    29
    thanx. i do have another question though. i've tried this before, but maybe i was doing something wrong. is it possible to use the
    VB Code:
    1. Private Sub Form_KeyDown()
    to call the
    VB Code:
    1. Private Sub Command1_GotFocus()

    i'm trying to make a menu screen on my game, and i would like to make it completely mouse free. (so far, i'm using the mouse to click the command buttons i have in battles)

  4. #4
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Originally posted by CapFlea03
    thanx. i do have another question though. i've tried this before, but maybe i was doing something wrong. is it possible to use the
    VB Code:
    1. Private Sub Form_KeyDown()
    to call the
    VB Code:
    1. Private Sub Command1_GotFocus()

    i'm trying to make a menu screen on my game, and i would like to make it completely mouse free. (so far, i'm using the mouse to click the command buttons i have in battles)
    If you do do that then the Command button won't actually take focus but it will run the code as if it had taken focus. If your wanting to give the button focus I think there is a set focus method .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  5. #5

    Thread Starter
    Junior Member CapFlea03's Avatar
    Join Date
    Apr 2004
    Location
    Dallas, Texas
    Posts
    29
    sorry, i got my questions mixed up. is it possible to push a button on the keyboard to "click" a command button?

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    You can always write a a & in front in the caption property of a command button. THen there will be a _ under the first letter, and the user can press Alt+The first letter in the name to click that button....

  7. #7

    Thread Starter
    Junior Member CapFlea03's Avatar
    Join Date
    Apr 2004
    Location
    Dallas, Texas
    Posts
    29
    yeah, thats how i moved around in my first game, and even though i told people to hold alt right at the beginning when the game first came up, everybody still got confused. i'm trying to move away from using alt to click a command button if thats possible.

  8. #8
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    If it is a game you should not use the command buttons at all...use the keyup key down events....tutorual in the FAQ...

  9. #9

    Thread Starter
    Junior Member CapFlea03's Avatar
    Join Date
    Apr 2004
    Location
    Dallas, Texas
    Posts
    29
    i know how do use the key up and key down events, and i've removed command buttons from most of my game, but what i'm trying to do right now is create a menu to show character stats and things. i'd like to have command buttons that change color when they have the focus, and have the player be able to push a set button (key down) which activates the current command button. like i said in an earlier post, i'm trying to get away from using the mouse completely.

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If it is a game you should not use the command buttons at all
    Nothing wrong with using command buttons, you can use the tab key to jump between all focusable objects and arrow keys for just for instance buttons..
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by kedaman
    Nothing wrong with using command buttons, you can use the tab key to jump between all focusable objects and arrow keys for just for instance buttons..
    for instance button?? But the probelm is that the arraw keys are moving the focus, and the click is not autoamticaly fetched by the event...

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by NoteMe
    for instance button?? But the probelm is that the arraw keys are moving the focus, and the click is not autoamticaly fetched by the event...
    theres a got focus event for that if i remember correctly
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by kedaman
    theres a got focus event for that if i remember correctly

    Yeah but that won't help you much. If you use that, you will still have to write the same code as if you are not using command buttons + some more. Becuase if you lay the buttons now in the order:

    Up - Right - down - Left


    And you are in the game, then the up arrow will have the focus, and if you then press the down arrow, then the RIGHT button will have the focus. and if oyu press the down button again, then the DOWN button will have the focus, and if you press the down arrow again, then the left button will have the focus.

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    ah so thats what you meant, but are you suppose to focus them or have the effect of clicking on them by pressing the arrow buttons?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15

    Thread Starter
    Junior Member CapFlea03's Avatar
    Join Date
    Apr 2004
    Location
    Dallas, Texas
    Posts
    29
    i want them to focus with the arrow keys, and click when the user presses a certain key, which i will designate.

  16. #16
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    and the order in which they are focused? You could set the focus accordingly I guess if you just subclass the buttons
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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