How to Rotate ellipse using single touch in WPF - wpf

Any idea how to Rotate an ellipse by single finger touch?
Here is my code:
private Point currentPoint;
private void MyEllips_OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
// RotateMe.Angle =
}
private void MyEllips_OnTouchMove(object sender, TouchEventArgs e)
{
currentPoint = e.GetTouchPoint(this).Position;
}
How to calculate touch point angle while moving?

Related

How can I change the scroll position of a richtextbox?

private void richTextBox1_VScroll(object sender, EventArgs e)
{
richTextBox2.?= richTextBox1.GetPositionFromCharIndex(0);
}
What should I put instead of "?" to set the scroll position of richTextBox1 on Y?
Or how else can I implement synchronous scrolling?

Drawing multiple polygons in canvas

I have a canvas, myCanvas where i want to draw multiple polygons on the location where i specify the points.
PointCollection polygonpoints = new PointCollection();
private void myCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//add polygon collection
Point p = e.GetPosition(MapGrid);
polygonpoints.Add(p);
}
private void myCanvas_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
Polygon poly = new Polygon();
poly.Points = polygonpoints;
poly.Fill = Brushes.AliceBlue;
MapCanvas.Children.Add(poly);
polygonpoints.Clear(); // this is making clear the polygon but the pointcollection is remain
}
polygonpoints.Clear - i planned to use this for clearing the polygon points for next polygon. but this is not happening.
Any suggestions please.
I believe the issue is you're passing polygonpoints rather than a copy of it as poly.Points.
Change the polygon creation to
Polygon poly = new Polygon
{
Points = new PointCollection(polygonpoints),
Fill = Brushes.AliceBlue
};

GMap.NET Windows Forms move the map with the mouse

How in GMapControl it is correct to handle pressing and moving Google maps using the mouse?
GMapControl gMap = new GMapControl();
gMap.MouseDown += GMap_MouseDown;
private void GMap_MouseDown(object sender, MouseEventArgs e)
{
gMap.MouseMove += GMap_MouseMove;
}
private void GMap_MouseMove(object sender, MouseEventArgs e)
{
base.OnMouseMove(e);
//gMap.Position = new PointLatLng(X, Y);
}
You don't need any code to move the map. The default is for the RIGHT mouse button to move the map, which I found rather awkward. To change to the LEFT mouse, use code like this in the Load() event of your Form:
gMap.DragButton = MouseButtons.Left;

How do I go about implementing drag delta on shapes

How do I go about implementing the drag delta on a Shape, I have the following code:
void Connector_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.ClickCount == 1)
{
this.Focus();
this.CaptureMouse();
this.RaiseEvent(new DragStartedEventArgs(0,0));
initMousePoint = e.GetPosition(this);
}
e.Handled = true;
}
void Shape2_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
currMousePoint = e.GetPosition(this);
if (this.IsMouseCaptured)
{
this.RaiseEvent(new DragDeltaEventArgs(0,0);
}
}
void Shape2_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.ReleaseMouseCapture();
}
Now for the DragDeltaEvent args do I need to compute the drag in the mousemove and pass it to the event, also is this the right way to raise the event. If this works, then I should only subscribe to the drag delta event and use it as a thumb? Note, I do not want to template the thumb with the shape, providing this answer won't help me.
note the chagnes, about the getting the position of the mouse, this I don't think works, because it gets the position relative to the element, not the containing panel, so I don't think i will be able to find the drag distance this way.
I solved it using:
currMousePoint = e.GetPosition(this);
double dragHorizontal = currMousePoint.X - initMousePoint.X;
double dragVertical = currMousePoint.Y - initMousePoint.Y;
//Set the new canvas top and left proeprties here.

how to GetMousePosition anywhere on the screen, outside the bounds of window (or any Visual)

I'd like to track the position of the Mouse cursor, in screen coordinates, anywhere on the screen. So even if the mouse cursor moves outside the bounds of the window, is there a way to get the position of the mouse cursor?
What I'm doing is trying to get a popup to follow the mouse cursor, even if it moves off the main window.
Here is a code snippet of what I've tried (and hasn't worked):
private void OnLoaded(object sender, RoutedEventArgs e)
{
bool gotcapture = this.CaptureMouse();
Mouse.AddLostMouseCaptureHandler(this, this.OnMouseLostCapture);
}
Point mouse_position_relative = Mouse.GetPosition(this);
Point mouse_screen_position = popup.PointToScreen(mouse_position_relative);
private void OnMouseLostCapture(object sender, MouseEventArgs e)
{
bool gotcapture = this.CaptureMouse();
this.textblock.Text = "lost capture.";
}
What exactly was your problem?
Wait! There is a way to position a Popup relative to the screen. see PlacementMode.AbsolutePoint
This showed little happy face flying around:
private Popup _popup;
public Window1()
{
InitializeComponent();
this.Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
_popup = new Popup
{
Child = new TextBlock {Text = "=))", Background = Brushes.White},
Placement = PlacementMode.AbsolutePoint,
StaysOpen = true,
IsOpen = true
};
MouseMove += MouseMoveMethod;
CaptureMouse();
}
private void MouseMoveMethod(object sender, MouseEventArgs e)
{
var relativePosition = e.GetPosition(this);
var point= PointToScreen(relativePosition);
_popup.HorizontalOffset = point.X;
_popup.VerticalOffset = point.Y;
}
Never mind, I realized there is no way to position a Popup relative to the screen, only relative to the Visual which contains it.
There are a number of ways to get the screen coordinates of the mouse position outside of a WPF Window. Unfortunately, you'll need to add references to use either of them, but it is possible. You can find examples of them both in #FredrikHedblad's answer to the How do I get the current mouse screen coordinates in WPF? question. Coincidentally, that question was answered a few days before you asked this question and gave up within 21 minutes of asking.

Resources