Pulling Coordinates from Mouse - c#

I'm working on a Screenshot Application(The one I liked, the developer dropped it).
Any whoo, I have the hot-key done, as well as saving the bmp->png and uploading it to my server. But I'm just not sure how to go about making a function that...
Freeze the Screen(Or rather, could I create some sort translucent overlay/window?)
Detects whether the user Left or Right Clicked on the Mouse
If the user right clicks, the screen is unfrozen and screenshot process is canceled
If the user left clicks it creates a border(1-2px) around the square(the screenshot area)
Pull the Coordinates(x, y) and width & height into integers
If anyone could give me some sort of direction, or where I should start looking around in the documentation I'd appreciate it.
Thanks,
Brandon

Related

Is there a way in a Blazor Server app to get mouse coordinates clicked

I am trying to get motivated to move one of my open source projects called Transparency Maker from Windows Forms to Blazor, so I can put the app online.
All of the image editing is done via text in a language called BQL (Bitmap Query Language) which is very similar to SQL.
The one thing I don't know how to do in Blazor is get the x, y position of where the image is clicked. Windows Forms makes this very simple, although I have to do some scaling.
Is there a JavaScript way of doing this and bringing it into Blazor?
This is a feature I have to have, or writing a query like this is impossible for the user to know what to type:
Update
Set Adjust Red -200
Where
X Between 1700 2591
Y Between 1930 2110
Total > 500
Notice the White part of the socks in the second image, only the white was changed because the Total (Red + Blue + Green) has to be greater than 500 to perform the adjustment.
Thanks if this is possible to get the position clicked?
I think more people might appreciate this tool once it is online. As it is, "selling" free software is actually harder than it should be.
Transparency Maker
https://github.com/DataJuggler/TransparencyMaker
I am posting an answer thanks to the help from dani (if you posted your answer here, I could mark it as the answer).
I had to do two things to make this work:
Add a using statement for
using Microsoft.AspNetCore.Components.Web;
I added the EventCallback e parameter, and I didn't have to change anything else.
public void Button_Clicked(MouseEventArgs e)
{
double x = e.ClientX;
}
I will probably have to write some trial and error code to go from where the image is located, to find what pixel was actually clicked, but now I am confident I can do this.
Many thanks Dani. I will name a hospital after you some day.

Setting up ZedGraph to chart analog signal data?

ZedGraph super users, I have done my best working with ZedGraph to make an analog signal chart. I need some help with the finishing touches.
Currently the graph "grows" from the left to the right as new data comes in (No real world data yet, just a random point every timer tick), if the data grows too large for the default zooming options then the data points are "compressed" on the graph and the right hand side shows more white space, and the X axis scales larger.
What I would like is for the data to grow from right to left (Basically "flip" the graph over the Y axis so +x is to the left and -x is to the right?). Also I would like a "sliding window" for the graph to show only the newest data from the source (basically a 5 second sliding window).
Does ZedGraph have the ability to implement either of these features by default?
Otherwise I plan to negate all of the time stamps on the data (I guess and never show the x axis?) so that the data "grows" from right to left as it comes in. For the sliding window, I was going to only keep (5sec/timeBetweenData) # of data points and remove the rest from the LineItem representing the signal and store them (in case I want to show them to the user again). But If I don't have to do that it would be nice.
So to fix this I did end up negating all of the time stamps so that the new data would "enter" the graph on the left and move to the right as it got older.
Then to create the sliding window effect I removed the oldest point in the graph for every point that I added.
Another unforeseen issue was that the GraphPane by default would add some padding in front of and behind the min and max points, so to fix this I found the minimum and maximum points in my curve and set the dimensions of the axis' scales to that.

Application, improve performance of touch events

Basically, I have an application witch is 8000px by 8000px. We can zoom in to view a specific part, example on the radio, or we can zoom out to view everything.
Each part of the car is a control that we can manipulate with fingers, on a dual touch or multitouch monitor.
My problem is: for manipulating a control, for example the Volume button, the user needs to move the mouse exactly like in real life, so with a circular movement.
With the mouse everything is perfect, it responds instantly without any delay. I use the OnMouseLeftButtonDown, OnMouseMove, etc.
With the touch, it seems to be very difficult for the computer to get the touch position and there is a huge lag, especially when the user move 2 different button with 2 fingers at the same time. I use the OnTouchDown, OnTouchMove, etc...
The only difference between the mouse and the touch is when we need to get the position, with the Mouse I use: (e is a MouseButtonEventArgs)
Point currentPosition = e.GetPosition(this);
With the Touch I use: (e is a TouchEventArgs)
Point currentPosition = e.GetTouchPoint(this).Position;
Everything after this is the same.
I don't know if it's because I have too many control in the my application (over 5000 that we can manipulate, but when we zoom in on only 2 control it's the same thing) or because it is really difficult for the computer to get the position from a touch event....
Can someone help me with this? I need to find a solution to eliminate the lag.
I use Visual Studio 2010, Blend 4, .NET 4.0
Windows 7 64-bit
7 Gb RAM
Xeon 2.13 Ghz, 2 core, 8 thread
Screen: ELO technology, in a NEC 2490WUXi2 screen
This seems to be a bug. Take a look at this post.
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/756a2ccf-6cf1-4e4a-a101-30b6f3d9c2c9/#ed51226a-6319-49f8-be45-cf5ff48d56bb
Or
http://www.codeproject.com/Articles/692286/WPF-and-multi-touch
it's hard to say why you have such an issue - may be OnTouchMove is triggered more often than MouseMove and you should create some additional processing to smooth the touch positions data.
I'd try to comment all the code under the
Point currentPosition = e.GetTouchPoint(this).Position;
and look at the performance.
Another approach is to count how much OnTouchMove is triggered.
The problem is the touch device, try another one to see if the lag is still there.

Design a TagVisualization for a control dial

I'd like to design a UI-Element, which gives the User the possibility to switch between different options. Therefore I want to use a Tangible which acts as control dial... I have already designed a Pointer and a Menu. The problem:
When the User rotates the Tangible, the Menu should stand still and the pointer should follow the rotation-movement. But when the User just moves the Tangible (without a rotation), the whole UI-Element should move.
Here a example for a non-Tangible control dial:
http://msdn.microsoft.com/en-us/library/ee804832%28v=surface.10%29.aspx
Does anyone know how to deal this with a TagVisualization?
Thanks in advance,
Chris
EDIT:
I've written a small tutorial, which can be viewed on: http://project-premium.org/
Set UsesTagOrientation=false on the TagVisualization or TagVisualizationDefinition
Inside the TagVisualization, monitor TrackedContact.Orientation to update your dial UI

Designing a CAD application

I am designing a CAD application using a variation of MVC architecture. My model and view are independent of each other. They communicate through the controller. My problem is if I need to draw an object (say line or polyline) I need a number of input points. What would be the best way to get the points? All the events from the view are subscribed by the controller and controller has to keep the points, then generate the line or polyline and finally add this line to view. But I dont know how capturing the mouse points be done efficiently, because each object will have different number of inputs and different algorithms of input validations.
Any help would be highly appreciated.
I was working in a CAD application 3 years ago, and these are some tips I remembered we have done (BTW: the application is free, you can download it, register your copy, and make use of the features in the Truss Editor):
1- You may add buttons for shape drawing, example: a button for a line, a button for a polyline, a rectangle, ...etc.
2- Create a variable that holds the current state your application (may be an enum): ready, drawing point, drawing line, drawing polyline, drawing circle, ...etc.
3- Wherever the user clicks a drawing button, the system enters a relevant state from those mentioned above.
4- The system returns to the "ready mode" when finished drawing, which can be detected automatically by the expected number of points (1 for point, 2 for line, 3 for ellipse, ...etc) or when the user presses Esc or right-clicked the drawing area (if the expected number of points is unknown, example: polyline). You may also end polyline drawing if the user re-clicked the first point and he has drawn 3+ points.
5- The system may cancel current drawing operation if the user ends the operation before completing the number of expected points.
...
when designing a CAD software, you must not only think of flexibility and dynamic, but also of speed. You should use some kind of wrapper class that works as a very thin layer between you and the hardware driver, it should return stuff like the pixel array of the screen, the current bpp, etc... This is how I would do it (and did actually). Now in C#, seeing as it is a .NET language, I'm not sure you can go that below, but you can still have someking of handler between the controller and your pen object, can't you?

Categories

Resources