Results 1 to 9 of 9

Thread: How to prevent focus on button after mouse click...

  1. #1

    How to prevent focus on button after mouse click...

    Hi, I have two buttons with onClick events on my form as well as a component that receives keyboard input. Problem is that when the left, right, up and down cursors are pressed focus jumps to and from the buttons and when the spacebar is pressed it performs the same function as the mouse click -- which I do not need :evil:

    How can I prevent delphi from moving focus to the buttons?
    Wake up from the dream and live your life to the full

  2. #2

    How to prevent focus on button after mouse click...

    Try setting button TabStop property to false.

  3. #3

    How to prevent focus on button after mouse click...

    The tabstop property is set to false, I even have dxDraw.setfocus. I did a lot of tests with all the gui properties of the button and the form and no joy.

    TabStop doesn't do a thing for my problem, do a simple test and place 3 buttons on a form -- try to move between them with the cursor keys on your keyboard, it's not moving focus right? That's all good and well but click on one of them (even without onclick event handler) and move the cursor keys.....No tabstop anymore... TabStop only works if you press Tab, not if the user clicks and then press the cursor keys.

    I want to stop the moving between the controls if a mouse click happens and the user then press the cursor keys. In my game the mouse click on a button will enable/disable music and directly after that the user must select (with the cursor keys) a further item to play or to close.

    I'm using 2 buttons on dxDraw but I don't think DelphiX has anything to do with the tab behaviour of the buttons.
    Wake up from the dream and live your life to the full

  4. #4

    How to prevent focus on button after mouse click...

    I've had that problem long time ago. Then another thing to try:
    form.Setfocus;
    Because DXDraw isn't something to give focus to if i recall.

  5. #5

    How to prevent focus on button after mouse click...

    Quote Originally Posted by Wizard
    I want to stop the moving between the controls if a mouse click happens and the user then press the cursor keys. In my game the mouse click on a button will enable/disable music and directly after that the user must select (with the cursor keys) a further item to play or to close.
    The simplest way to do this is is to just do a setfocus in the onClick event handler of each button eg.

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Music_Off;
    Form1.SetFocus;
    end;

    If you then disable the tabstop for the buttons to prevent them getting focus any other way, it should work nicely.
    I tested this with a Tmemo component and three buttons, and I think it does what you want it to.


    [edit]
    scratch that, I just tested it with a dxDraw component, and it dont work, I think dxdraw wont take the input focus, because it doesn't handle input itself
    Check out my Delphi programs, music and writing.
    <br />http://digitalfunnybone.com/Programming.html

  6. #6

    How to prevent focus on button after mouse click...

    ok try this :

    put a Tedit component on your form and resize it to 10x10

    clear the text

    switch off ctl3d for the edit box

    Set the borderstyle = bsNone

    set the color to the background color of your form (makes it invisible)

    then in the onclick event of each button, do :

    Edit1.setfocus;


    make sure you switch off tabstop for all buttons and the editbox to stop the buttons getting focus accidentally.

    I'm not sure if the editbox will prevent the dxinput from recieving messages but I shouldn't think so.

    The only other way I know is to hook the windows message, but that way is a bit compicated.
    Check out my Delphi programs, music and writing.
    <br />http://digitalfunnybone.com/Programming.html

  7. #7

    re-

    finish your ONclick button event with this:

    ActiveControl:=nil;

  8. #8

    Re: re-

    Quote Originally Posted by tpascal
    finish your ONclick button event with this:

    ActiveControl:=nil;
    nice one.. thats an even better way.
    Check out my Delphi programs, music and writing.
    <br />http://digitalfunnybone.com/Programming.html

  9. #9

    How to prevent focus on button after mouse click...

    Thanks for the replies guys :-)

    ActiveControl := Nil works 100%, problem solved!
    Wake up from the dream and live your life to the full

Bookmarks

Posting Permissions

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