[Solved]Component to get mouse location(when mouse down)with C# in visual studio

Hello everyone.
I am trying to get mouse location with Rhino.UI.MouseCallbackEventArgs and its ViewportPoint property.
Here is my code in cs file:
MouseDown.cs (1.4 KB)
And here is my code in screenshots:

I think I am getting many things wrong. I am pretty new to C# and its “class”.
The code did not work as expected.
Also I found it really difficult to find what I want in rhinocommon.sdk. Many pages showed me "Missing

documentation " and the only way I can do is trying with different approaches.

Is there any idea how I can proceed with this task?

Thank you very much!

Already available as a compiled component
here: Mouse component under util


1 Like

point = mousedown.pt only happens once each new solution, and when it happens, your mouse is not in the viewport, so you are not updating that variable properly. You need a timer or something that updates the component state (the point variable and its output) as often as you wish and also assign the variable from SolveInstance and also create the MouseDownClass once per component instance life (maybe it should be a static instance within the component class?).

1 Like

Thank you eddi!
I have found 2-3 plugin with similar function.
But still I am trying to get behind it and work out the code myself.
Thank you anyway! This plugin is nice.

Thank you very much! You are damn right.
My code has some real “time” issue. BeforeSolveInstance only run once and my code will be come useless if everything just run once.
For SolveIntance you just remind me that I have to add something like ExpireSolution(true);

I search for some clue about “C# detect mouse down” and I found some simple solution with System.Windows.Forms.

There are Control.MouseButtons and Cursor.Position in System.Windows.Forms.
So useful and much more elegant.

Here is my working code:

Thank you again for your help!