Is there any alternative to DragOver to suppress glyph on drag drop? - c#

I have a UWP App (a game). The entire App surface is a Win2D AnimatedCanvasControl with Drag/Drop enabled.
I have coded a DragOver handler to suppress the framework caption ("Move"/"Copy"/etc.) and glyph.
private void CnvGemSmash_DragOver (Object sender, DragEventArgs e)
{
e.AcceptedOperation = DataPackageOperation.None;
e.DragUIOverride.IsCaptionVisible = false;
e.DragUIOverride.IsGlyphVisible = false;
This works - BUT not until after about a 1 second delay after the drag starts. I've scoured the APIs looking for a way to avoid the glyph appearing for that fraction of a second - it looks awful in my App.
Is there any way around this?

What I'm taking from them is that I cannot suppress the glyph on DragStarting as the version of DragUI which is passed into that event doesn't expose the glyph.
The reason is that the item hover area is not support drop when Drag Starting. It is by design.

Related

How to move a textbox with mouse click in Universal Windows Platform (UWP) app

I am trying to move a textbox that is the child of a Canvas by clicking and dragging with a mouse or touching and dragging on a windows Surface device. I have tried using TextBox.Manipulation data, as well as PointerPressed, PointerMoved and PointerReleased but none of these have proven successful. Are there any suggestions for how to use either of these methods of moving a text box? Or, are there any suggestions using a different approach?
Thanks
XAML Manipulation mode needs to be set.
ManipulationMode="TranslateX, TranslateY"
ManipulationDelta="SomeControl_ManipulationDelta"
Then code behind.
private void SomeControl_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var uiEle = sender as UIElement;
var change = e.Delta.Translation;
var left = Canvas.GetLeft(uiEle);
var top = Canvas.GetTop(uiEle);
left += change.X;
top += change.Y;
Canvas.SetLeft(uiEle, left);
Canvas.SetTop(uiEle, top);
}
The above sample is from vs2017 with target/min of build 16299.
The code provided doesn't prevent dragging off screen so you may want to implement a clamp mechanism for the new left and top values or some other means of preventing the control being dropped in non visible space.

Missing 'Text Cursor Moved' and 'Scrollbar Adjusted' events in .NET Scintilla component?

Like the RichTextBox, I want to be able to handle events for when the vertical scrollbar has been adjusted (through slider dragging, the mouse wheel or otherwise), and for when the caret / text cursor has been moved. However, these events appear to be missing from Scintilla. How can I achieve the same result?
Both of those are available under the UpdateUI event via the UpdateChange structure. Example:
private void scintilla1_UpdateUI(object sender, ScintillaNET.UpdateUIEventArgs e)
{
if (e.Change == ScintillaNET.UpdateChange.VScroll)
{
...
}
}

KinectRegion HandPointer Cursor as mouse cursor in Awesomium Browser

I would like to use the kinect hand cursor as 'normal' mouse cursor. In the specific I want to be able to interact with the Awesomium browser object.
The problem is that no Awesomium Browser event is raised when the kinect hand cursor is (for example) over a link, or I do a click, or any other typical mouse event.
I modified the Control Basics-WPF example program that you can find in the example directory of the Kinect SDK
I am using c# visual studio 2012, Kinect SDK 1.7, Awesomium 1.7.1.
It's been a month since this question's been asked, so perhaps you've already found your own solution.
In any case, I found myself in this scenario as well, and here was my solution:
Inside MainWindow.xaml, you'll need the Awesomium control inside a KinectRegion (from the SDK).
You'll have to somehow tell the SDK that you want a control to also handle hand events. You can do this by adding this inside MainWindow.xaml.cs on the Window_Loaded handler:
KinectRegion.AddHandPointerMoveHandler(webControl1, OnHandleHandMove);
KinectRegion.AddHandPointerLeaveHandler(webControl1, OnHandleHandLeave);
Elsewhere in MainWindow.xaml.cs, you can define the hand handler events. Incidentally, I did it like this:
private void OnHandleHandLeave(object source, HandPointerEventArgs args)
{
// This just moves the cursor to the top left corner of the screen.
// You can handle it differently, but this is just one way.
System.Drawing.Point mousePt = new System.Drawing.Point(0, 0);
System.Windows.Forms.Cursor.Position = mousePt;
}
private void OnHandleHandMove(object source, HandPointerEventArgs args)
{
// The meat of the hand handle method.
HandPointer ptr = args.HandPointer;
Point newPoint = kinectRegion.PointToScreen(ptr.GetPosition(kinectRegion));
clickIfHandIsStable(newPoint); // basically handle a click, not showing code here
changeMouseCursorPosition(newPoint); // this is where you make the hand and mouse positions the same!
}
private void changeMouseCursorPosition(Point newPoint)
{
cursorPoint = newPoint;
System.Drawing.Point mousePt = new System.Drawing.Point((int)cursorPoint.X, (int)cursorPoint.Y);
System.Windows.Forms.Cursor.Position = mousePt;
}
For me, the tricky parts were:
1. Diving into the SDK and figuring out which handlers to add. Documentation wasn't terribly helpful on this.
2. Mapping the mouse cursor to the kinect hand. As you can see, it involves dealing with System.Drawing.Point (separate from another library's Point) and System.Windows.Forms.Cursor (separate from another library's Cursor).

Double click timer event

I am developing an application that maps users eye movements with the cursor movements, hence developing ahands free cursor control system.
I am using Open CV library's .NET Wrapper for C# i.e. Emgu CV for development.
I am stuck at a point where I want to open a file/folder such that when a cursor is placed over a file/folder for say 3 to 5 seconds, the file/folder should open up or just perform a double-click event of a conventional mouse.
What could I use so as to solve this problem?
Timer timer = new System.Timers.Timer(5000);//5 seconds
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
private void form_MouseHover(object sender, System.EventArgs e)
{
timer.Start();
}
private void form_MouseLeave(object sender, System.EventArgs e)
{
timer.Stop();
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
timer.Stop();
OpenFileOrFolder();//Edit : implement your file / folder opening logic here
}
I guess you need to break it down:
Detect when the mouse moves or hovers
Send a double click
For 1, I'd be looking at: capturing WM_MOUSEMOVE if you want your own definition of 'hovering'. For example, having a greater threshold for how much movement you'll tolerate and still consider it a 'hover'. Or, you could use the OS defined threshold and look for WM_MOUSEHOVER
For 2, SendInput should get you there
I'm assuming here, you don't actually care what's under the mouse per-se. As in, you're not going to do different behavior depending on what's under the mouse. For example, you'd send the double click when hovering over the titlebar, as well as if you were hovering over the file.
This article on project builds up a Spy++ style app, which should help.
Are you mapping eye control to the mouse pointer? The MouseHover event may be useful:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousehover.aspx
As well as MouseEnter, MouseLeave, etc.
If you're controlling a separate element (i.e., not the mouse) with the eyes, then I had to do something similar in WPF. It ultimately came down to mapping control coordinates to mouse location, counting the time within the bounds of that control, then calling the mouse click event handler.

C# Drag and Drop Effect with Overlay/Opaque Image

I think this would be simple question and should be asked in the pas few years but unable to google around and dont know if there is a specific keyword.
In c# WinForm I want to do drag and drop but I dont want the image of DragDropEffects Move, Copy or whatever. I want to display an image with half opaque. Just like Firefox when dragging an image, you would see the image folowing the mouse pointer like a ghost :)
I already Implement DoDragDrop, DragEnter and DragDrop events. I just want to customize the dragging effects with overlay image.
Might be 9 years too late to the party 😄
I always liked Drag&Drop interactions but found it complicated to use in WinForms. Especially if you want it to look professional with overlays.
I made my own library for WinForms the last time I needed Drag&Drop. You can find it here or on NuGet:
https://github.com/awaescher/FluentDragDrop
Here's everything you need to implement Drag&Drop like shown above:
private void picControlPreviewBehindCursor_MouseDown(object sender, MouseEventArgs e)
{
var pic = (PictureBox)sender;
pic.InitializeDragAndDrop()
.Copy()
.Immediately()
.WithData(pic.Image)
.WithPreview().BehindCursor()
.To(PreviewBoxes, (target, data) => target.Image = data);
// Copy(), Move() or Link() to define allowed effects
// Immediately() or OnMouseMove() for deferred start on mouse move
// WithData() to pass any object you like
// WithPreview() to define your preview and how it should behave
// BehindCursor() or RelativeToCursor() to define the preview placement
// To() to define target controls and how the dragged data should be used on drop
}

Categories

Resources