By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,345 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,345 IT Pros & Developers. It's quick & easy.

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

P: n/a

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 ToolStripButtons.

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(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim frm As New Form1
frm.Show()
End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripButton1.Click
MsgBox("Click1")
End Sub

Private Sub ToolStripButton2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripButton2.Click
MsgBox("Click2")
End Sub

Private Sub ToolStripButton3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripButton3.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

Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies

P: n/a

"Joergen Bech" <jb***@post1.tele.dkwrote in message
news:h9********************************@4ax.com...
>
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 ToolStripButtons.

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(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim frm As New Form1
frm.Show()
End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripButton1.Click
MsgBox("Click1")
End Sub

Private Sub ToolStripButton2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripButton2.Click
MsgBox("Click2")
End Sub

Private Sub ToolStripButton3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripButton3.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

Jun 27 '08 #2

P: n/a
On Mon, 28 Apr 2008 18:27:23 -0400, "Lloyd Sheen" <a@b.cwrote:
>
"Joergen Bech" <jb***@post1.tele.dkwrote in message
news:h9********************************@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:
http://blogs.msdn.com/rickbrew/archi...09/511003.aspx

/JB

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.