ToolStripButton does not fire click event if form does not have focus?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joergen Bech

    ToolStripButton does not fire click event if form does not have focus?


    Hope someone has a solution or some suggestions for this.
    This cannot be right?!?

    Problem:

    I have multiple non-modal forms open at the same time.

    One or more of these forms have a ToolStrip, each of which has
    one or more ToolStripButton s.

    If, say, form A has got the focus and I click a ToolStripButton on
    form B, the button does not react at first: What happens is that
    form B gets the focus on the first click and THEN I have to click
    a second time for the ToolStripButton to fire its Click event.

    If form B already had the focus, the Click event would fire the
    first time.

    The following code illustrates the problem:

    Create a new project, add a Button control, a ToolStrip control,
    and on the ToolStrip control, three ToolStripButton controls
    (or one, for that matter) and paste the code below into form1.

    Run the program and click the button to create a second form.
    Now try getting a ToolStripButton control to fire its click event
    without the form on which it resides having the focus first.

    ---snip---
    Option Explicit On
    Option Strict On

    Public Class Form1
    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
    As System.EventArg s) Handles Button1.Click
    Dim frm As New Form1
    frm.Show()
    End Sub

    Private Sub ToolStripButton 1_Click(ByVal sender As System.Object,
    ByVal e As System.EventArg s) Handles ToolStripButton 1.Click
    MsgBox("Click1" )
    End Sub

    Private Sub ToolStripButton 2_Click(ByVal sender As System.Object,
    ByVal e As System.EventArg s) Handles ToolStripButton 2.Click
    MsgBox("Click2" )
    End Sub

    Private Sub ToolStripButton 3_Click(ByVal sender As System.Object,
    ByVal e As System.EventArg s) Handles ToolStripButton 3.Click
    MsgBox("Click3" )
    End Sub

    End Class
    ---snip---

    Regards,

    How do I get the ToolStripButton to fire its click event regardless of
    whether its form already has got the focus?

    (Note: There is no problem clicking the normal button, form focus or
    not.)

    ?

    TIA,

    Joergen Bech



  • Lloyd Sheen

    #2
    Re: ToolStripButton does not fire click event if form does not have focus?


    "Joergen Bech" <jbech@post1.te le.dkwrote in message
    news:h9bc14lrju 7o02noon4f8ocbd hpg1ijjle@4ax.c om...
    >
    Hope someone has a solution or some suggestions for this.
    This cannot be right?!?
    >
    Problem:
    >
    I have multiple non-modal forms open at the same time.
    >
    One or more of these forms have a ToolStrip, each of which has
    one or more ToolStripButton s.
    >
    If, say, form A has got the focus and I click a ToolStripButton on
    form B, the button does not react at first: What happens is that
    form B gets the focus on the first click and THEN I have to click
    a second time for the ToolStripButton to fire its Click event.
    >
    If form B already had the focus, the Click event would fire the
    first time.
    >
    The following code illustrates the problem:
    >
    Create a new project, add a Button control, a ToolStrip control,
    and on the ToolStrip control, three ToolStripButton controls
    (or one, for that matter) and paste the code below into form1.
    >
    Run the program and click the button to create a second form.
    Now try getting a ToolStripButton control to fire its click event
    without the form on which it resides having the focus first.
    >
    ---snip---
    Option Explicit On
    Option Strict On
    >
    Public Class Form1
    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
    As System.EventArg s) Handles Button1.Click
    Dim frm As New Form1
    frm.Show()
    End Sub
    >
    Private Sub ToolStripButton 1_Click(ByVal sender As System.Object,
    ByVal e As System.EventArg s) Handles ToolStripButton 1.Click
    MsgBox("Click1" )
    End Sub
    >
    Private Sub ToolStripButton 2_Click(ByVal sender As System.Object,
    ByVal e As System.EventArg s) Handles ToolStripButton 2.Click
    MsgBox("Click2" )
    End Sub
    >
    Private Sub ToolStripButton 3_Click(ByVal sender As System.Object,
    ByVal e As System.EventArg s) Handles ToolStripButton 3.Click
    MsgBox("Click3" )
    End Sub
    >
    End Class
    ---snip---
    >
    Regards,
    >
    How do I get the ToolStripButton to fire its click event regardless of
    whether its form already has got the focus?
    >
    (Note: There is no problem clicking the normal button, form focus or
    not.)
    >
    ?
    >
    TIA,
    >
    Joergen Bech
    >
    >
    >
    That is windows. There used to be an option in the mouse dialog that
    allowed a emulation ( I believe of X-Windows) where when you moved the mouse
    over a window it gained focus. I don't see that in Vista. You will get
    behaviour in any windows app.

    You could capture the mouse enter event and give focus to you app (the
    appropriate window) and that would get rid of the standard behaviour.

    LS

    Comment

    • Joergen Bech

      #3
      Re: ToolStripButton does not fire click event if form does not have focus?

      On Mon, 28 Apr 2008 18:27:23 -0400, "Lloyd Sheen" <a@b.cwrote:
      >
      >"Joergen Bech" <jbech@post1.te le.dkwrote in message
      >news:h9bc14lrj u7o02noon4f8ocb dhpg1ijjle@4ax. com...
      >>
      ---snip---
      >
      >That is windows. There used to be an option in the mouse dialog that
      >allowed a emulation ( I believe of X-Windows) where when you moved the mouse
      >over a window it gained focus. I don't see that in Vista. You will get
      >behaviour in any windows app.
      >
      >You could capture the mouse enter event and give focus to you app (the
      >appropriate window) and that would get rid of the standard behaviour.
      >
      >LS
      Sorry, but I do not understand what you mean.

      I have not seen any similar behavior in other programs, so this
      is definitely not standard Windows behavior.

      In other applications I have no problems switching to
      another form by clicking on a tool button or control.

      But never mind. I found this link, which explains it all:


      /JB



      Comment

      Working...