MaxScript event handers for dotNetControls?

I’ve placed a (custom) .NET slider control (“trackbar” in Windows.Forms parlance) on my MaxScript dialog. I want to be able to detect a click&drag event on the slider and update a MaxScript spinner appropriately. The problem is I can’t figure out how to detect the event.

I thought I’d use the dotNet.AddEventHandler() method, but that only works for dotNetObjects, not dotNetControls. I’ve had limited success using a MaxScript event handler, like:

on tb_Test click do (
messageBox “Click worked!”
)

That works, but on fires off on the end of a click event (e.g. mouseUp). It isn’t appropriate for polling the control during a mouse move event.

For activeX controls Max has quite a few native event handlers like Click, KeyDown, KeyPress, KeyUp, BeforeClick, OLEStartDrag, OLECompleteDrag, OLEDragOver, etc… Other than Click none of these seem to work with my .NET trackbar control.

How do I go about making a workable event handler for this control?

It seems that the three events that I needed to override in my custom control, MouseDown, MouseUp, and MouseMove are no longer valid from outside of the control. I need to figure out how I can override them without making them protected.

Did you try looking at Bobo’s MXS DotNet reference?

http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Windows.Forms.TrackBar.html

There are also a couple DotNet things on the Wiki:
http://tech-artists.org/wiki/index.php/Category:DotNet

Bobo’s list of events for the TrackBar control jive with what I see in the Listener when I do a showEvents <dotnetcontrol> on my custom control. The methods I’ve overridden in C# are listed. They just don’t respond to an MXS event handler that calls them. If I comment out my overridden events, recompile my control, and try those events from within an MXS event handler then Max can successfully use them. The act of overriding the events to make custom ones seems to be the cause of my problem.

I tried making the overriden events public override instead of protected override in C#. The compile complained about that pretty heavily, though.

I’m going to make a small C# app that uses my control to see of my overridden events are accessible to C# or not. If they are accessible there, but not to MXS then I’ll be unhappy, as that could point to an error in the .NET implementation inside of MXS.

Hey Jeff,

Interestingly I just run into a similar situation. Basically implemented a global key interceptor, and created an event for this. It works perfectly in C#, but in Maxscript it just throws an error that my class doesn’t have the specified event, which is listed when I use ShowEvents method of Maxscript.

So I guess registering Maxscript methods to custom events doesn’t seem to be possible.

Light

I got this all figured out with the help of some people over at area.autodesk.com. When I overrode the mousemove event I didn’t explicitly raise the event at the end of my new method. There were also a few issues with the fact that I was trying to override an event in the mouse events class with a different class for the event arguments. I wrote a new custom event that took the new event arguments class and explicitly raise that at the end of my mouseMove event. MaxScript see that and interacts with it just fine.

All in all, making a custom Windows.Forms control in C# is far easier than I thought it would be. I’m working on a a WIKI post for here that will cover the basics.

I cant wait to see this jeff, I am interested in doing something similar in 3dsmax