Button clicks get ignored by a .NET ToolStrip control when window doesn't have focus

Button clicks get ignored by a .NET ToolStrip control when window doesn't have focus

Anonymous
Not applicable
935 Views
6 Replies
Message 1 of 7

Button clicks get ignored by a .NET ToolStrip control when window doesn't have focus

Anonymous
Not applicable
I have an issue where I can't get a click to pass through to a toolstrip button unless the rollout is focused. To repro the bug, run my code in Max 9+ and click off of the Test rollout and then click the ToolStrip button without having the rollout focused. You'll see that the other two buttons do behave correctly, with the .NET button receiving the click. It seems it is just a problem with the ToolStrip. Is there something on the ToolStrip that I have to set to get that event to pass through?

Here is my code:

rollout test "Test"
(
button theButton "Press me!" width:50 height:50 pos:

on theButton pressed do
(
messagebox "Remember: Never press unknown buttons!"
)

dotNetControl theDotNetButton "Button" width:50 height:50 pos:

on theDotNetButton Click sender evedntargs do
(
messagebox "Remember: Never press unknown .NET buttons!"
)

--dotNetControl toolStripContainer "ToolStripContainer" width:120 height:50 pos:
dotNetControl toolStrip "ToolStrip" width:120 height:50 pos:

fn ToolStripButtonClick button e =
(
messagebox "Remember: Never press unknown .NET ToolStrip buttons!"
)

on test open do
(
theDotNetButton.Text = ".NET!"

--toolStrip = dotNetObject "ToolStrip"
format "Visible: % Width: % Height: %\n" toolStrip.visible toolStrip.width toolStrip.height
toolStrip.text = "I'm a tool strip"
obj = dotNetObject "ToolStripButton"
obj.width = 50
obj.height = 50
obj.tooltiptext = "ToolTipText"
obj.text = "Tool Strip Button"
dotnet.addeventhandler obj "Click" ToolStripButtonClick
toolStrip.items.add obj
--toolStripContainer.TopToolStripPanel.Controls.Add toolStrip
)
)
createDialog test 150 150
0 Likes
936 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
I've got this problem as well but it's not just toolstrips, I think it's any kind of control array, the saem thing happens with menus for example. I'll be looking into this soon...

G
0 Likes
Message 3 of 7

Anonymous
Not applicable
I've got this problem as well but it's not just toolstrips, I think it's any kind of control array, the saem thing happens with menus for example. I'll be looking into this soon...

G


The only workaround I can think of right now is to focus the window OnMouseHover:


on toolStrip MouseHover do
(
toolStrip.Focus()
)


It still takes a moment to focus the window, however, for most purposes it'll do the trick.

::Amir
0 Likes
Message 4 of 7

Anonymous
Not applicable
If this is some kind of problem where event messages are being blocked by these controls you should be able to subclass the controls (in C# or whatever) and force the messages through. I've been looking into making a DLL that has a bunch of standard windows controls that have some added maxscript friendly functionality. For example I've made my own form class where the constuctor takes a windows handle and the form parents its self to that hwnd (you give Max's hwnd and it acts more like a maxscript window). Sorry for getting off topic.

G
0 Likes
Message 5 of 7

Anonymous
Not applicable
This is a .NET form/control problem not a maxscript one. I just tested this out with a simple C# test app and you get exactly the same problem: Click event is not passed on to toolStrip buttons when the form doesn't initially have focus.
0 Likes
Message 6 of 7

Anonymous
Not applicable
And here's the answer:
http://blogs.msdn.com/rickbrew/archive/2006/01/09/511003.aspx

This will be useful if you can create your own .Net DLLs and distribute them with your scripts, if not then bad luck.

Give me a yell if you can't make your own DLL with this added code and I'll spit one out.

G
0 Likes
Message 7 of 7

Anonymous
Not applicable
Thanks for the feedback. Distributing .NET DLLs is possible, however, a bit of overkill for fixing this problem. It's not so much a major problem as it is a nuisance. I appreciate you checking this out in C#.
0 Likes