A problem with Trackbar OnKeyDown on a Form

Hi
I have a form and a Trackbar on it. Both of them has an OnKeyDown event. As you may know better, at the run-time, if we press a key, only the OnKeyDown of Trackbar occures. But how we can able to choose each of them to be active? For example if i=1 then we want to active the OnKeyDown of the Form and if i=0 we wan to active the relevant event of the trackbar. Please note that it is not possible to disable the trackbar. Now, Could you please help me by an example? Thanks

Comments

  • You can set the KeyPreview property of the form to True. Then the form will get the event first.

    : Hi
    : I have a form and a Trackbar on it. Both of them has an OnKeyDown event. As you may know better, at the run-time, if we press a key, only the OnKeyDown of Trackbar occures. But how we can able to choose each of them to be active? For example if i=1 then we want to active the OnKeyDown of the Form and if i=0 we wan to active the relevant event of the trackbar. Please note that it is not possible to disable the trackbar. Now, Could you please help me by an example? Thanks
    :
    :

  • : You can set the KeyPreview property of the form to True. Then the form will get the event first.
    :
    : : Hi
    : : I have a form and a Trackbar on it. Both of them has an OnKeyDown event. As you may know better, at the run-time, if we press a key, only the OnKeyDown of Trackbar occures. But how we can able to choose each of them to be active? For example if i=1 then we want to active the OnKeyDown of the Form and if i=0 we wan to active the relevant event of the trackbar. Please note that it is not possible to disable the trackbar. Now, Could you please help me by an example? Thanks
    : :
    : :
    :
    :
    Thank you very much for your help. But when I set the KeyPreview of the form to True, both the form and the trackbar receive the keyboard events.But Only the form receives it first. For example when I press the right arrow key , the OnKeyDown event of the form occures and the slider of the trackbar moves too! But I want to only the form recieves the keyboard events when for example i=1 (The Trackbar's Slider shouldn't change in this case)and when i=0 then the user can change the position of the Trackbar's Slider and so deactive the Form's OnKeyDown. Also please note that, Delphi help says that Navigation keys such as Arrow Keys are unaffected by KeyPreview. But I need them! In the other words, I need to change the focus or active control between the form itself and the trackbar or any another control. Now, what is your solution to do so? Thanks
  • : : You can set the KeyPreview property of the form to True. Then the form will get the event first.
    : :
    : : : Hi
    : : : I have a form and a Trackbar on it. Both of them has an OnKeyDown event. As you may know better, at the run-time, if we press a key, only the OnKeyDown of Trackbar occures. But how we can able to choose each of them to be active? For example if i=1 then we want to active the OnKeyDown of the Form and if i=0 we wan to active the relevant event of the trackbar. Please note that it is not possible to disable the trackbar. Now, Could you please help me by an example? Thanks
    : : :
    : : :
    : :
    : :
    : Thank you very much for your help. But when I set the KeyPreview of the form to True, both the form and the trackbar receive the keyboard events.But Only the form receives it first. For example when I press the right arrow key , the OnKeyDown event of the form occures and the slider of the trackbar moves too! But I want to only the form recieves the keyboard events when for example i=1 (The Trackbar's Slider shouldn't change in this case)and when i=0 then the user can change the position of the Trackbar's Slider and so deactive the Form's OnKeyDown. Also please note that, Delphi help says that Navigation keys such as Arrow Keys are unaffected by KeyPreview. But I need them! In the other words, I need to change the focus or active control between the form itself and the trackbar or any another control. Now, what is your solution to do so? Thanks
    :
    You can "remove" the key press by setting the Key parameter to 0. Then the scrollbar shouldn't recieve the key anymore.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories