473,387 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 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
2 7148

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
1
by: shland | last post by:
Is there a way I can trigger the click event of a button while I'm processing (server-side) the click of another button? I know this is available in Windows forms, but what about ASP.NET? ...
1
by: shland | last post by:
This is related to my previous post on "fire click event from serverside code?" Alternately, is there a way to intercept a click event on a control from a referenced .dll, and do some...
3
by: JD | last post by:
Hello, I have a problem with checkboxlist inside Repeater (in ASP.NET page). I am able to create Checkboxlist and bind it (inside Repeater_ItemBound - including setting checked/unchecked)....
3
by: TCORDON | last post by:
Why does the click event of an image button that submitts a form does not get fired when ENTER is pressend on a textbox of that form? How can I make this happen? Thanks
1
by: Andy Rose | last post by:
..Hi all, I want to catch an 'enter' keypress event on a web form and submit the form as if a button had been clicked rather than the default post back behaviour. I know the following javascript...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
3
by: LDD | last post by:
Hey folks I have some interesting behaviour going in. Inside a form, I download some data. The form is used to show the status, and set button states etc... I have a break point set up at...
2
by: Sunny | last post by:
Hi, I have an application using IE6 before and now we have upgraded to IE7. After upgrading, I have been having issues with button click event when embedded JavaScript file into the page....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.