cursor-position

How to get/set the position of the mouse relative from the application window?

蹲街弑〆低调 提交于 2019-12-11 09:37:30
问题 I want to be able to get the current location of the mouse pointer, relative from where my form window is. So if I would put my mouse on the top left of the form, it would give me the x and y values of x=0 and y=0, while the form itself might be in the middle of the screen. Also I want to set the position of the mouse. How can this be done in C#? I'm using a windows forms application. 回答1: Obtain the screen coordinates by using Cursor.Position, then convert to window coordinates invoking

Place tags around certain text within contenteditable without moving cursor

左心房为你撑大大i 提交于 2019-12-11 05:40:14
问题 I am working on a simple (I thought) word processor. It uses contenteditable. I have a list of words that I want to always appear highlighted. <article contenteditable="true" class="content"> <p>Once upon a time, there were a couple of paragraphs. Some things were <b>bold</b>, and other things were <i>italic.</i></p> <p>Then down here there was the word highlight. It should have a different color background.</p> </article> So basically what I need is a way to wrap a word in <span> tags. This

How to limit cursor movement in WPF based app?

浪尽此生 提交于 2019-12-11 03:28:50
问题 I'm working with a WPF app, more specifically a Canvas with draggable elements. Once an item is being dragged, I'd like to limit the scope of cursor movement to inside the canvas where the items are being dragged about. The event which can start a drag is shown below private void WidgetCanvas_PreviewHeaderLeftMouseDown(object sender, MouseButtonEventArgs e) { e.Handled = true; ... logic to figure out if this is a valid drag, blah blah blah ... this.IsDragging = true; // TODO: clip the

GetChildAtPoint method is returning the wrong control

非 Y 不嫁゛ 提交于 2019-12-10 19:14:23
问题 My form hierarchy is something like this: Form -> TableLayoutOne -> TableLayoutTwo -> Panel -> ListBox In the MouseMove event of the ListBox, I have code like this: Point cursosPosition2 = PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)); Control crp = this.GetChildAtPoint(cursosPosition2); if (crp != null) MessageBox.Show(crp.Name); The MessageBox is showing me "TableLayoutOne", but I expect it to show me "ListBox". Where in my code am I going wrong? Thanks. 回答1: The

Get contentEditable caret index position

℡╲_俬逩灬. 提交于 2019-12-10 19:12:44
问题 I'm finding tons of good, crossbrowser anwers on how to SET the cursor or caret index position in a contentEditable element, but none on how to GET or find its index... What I want to do is know the index of the caret within this div, on keyup . So, when the user is typing text, I can at any point know its cursor's index within the contentEditable element. EDIT: I'm looking for the INDEX within the div contents (text), not the cursor coordinates. <div id="contentBox" contentEditable="true"><

How do you move the cursor to the next element in a contenteditable div in Chrome/Safari?

走远了吗. 提交于 2019-12-10 18:52:22
问题 I have logic to insert a tag in a contenteditable div. I want to set the cursor to the start of the following element after the insertion. The code I have to do this is: function insertNodeAtCaret(node) { if(typeof window.getSelection !== 'undefined') { var sel = window.getSelection(); if(sel.rangeCount) { var rng = sel.getRangeAt(0); rng.collapse(false); rng.insertNode(node); // The following doesn't work in Chrome or Safari node = node.nextSibling; rng.setEndAfter(node); rng.setStartAfter

C# WPF application .NET 4.5 Set Mouse Position [duplicate]

雨燕双飞 提交于 2019-12-10 14:07:17
问题 This question already has answers here : How to move mouse cursor using C#? (2 answers) Closed 5 years ago . First time asking a question here, the solutions I found on here do not seem to work for some reason. My app needs to set the mouse position when the window becomes active, I have the function set up but cannot get cursor properties to work. I can't use Cursor.Position or anything really for some reason. I had hoped to visit the chat rooms to find a solution but apparently I cannot

Mouse Cursor position changes

走远了吗. 提交于 2019-12-10 11:14:10
问题 Hi I have a windows form application which i want to move my mouse then dragdrop will function but i have tried using mousemove mouse event to do it , but seems like dragdrop is very sensitive.So what i'm asking is whether is it possible to detect if the mouse cursor moves at least a certain distance away from the current cursor then it does the dragdrop code. 回答1: I understand you have a drag & drop code you want to execute only if the mouse has moved a certain distance. If so: You can hook

Snap to grid mouse locking up

删除回忆录丶 提交于 2019-12-09 21:09:53
问题 I am working on an application which draws a simple dot grid. I would like the mouse to snap between the points on the grid, eventually to draw lines on the grid. I have a method which takes in the current mouse location (X,Y) and calculates the nearest grid coordinate. When I create an event and attempt to move the mouse to the new coordinate the whole system becomes jerky. The mouse doesn't snap smoothly between grid points. I have copied a code sample below to illustrate what I am

how can i get selectedRange.location value?

为君一笑 提交于 2019-12-08 17:06:27
i want to get a cursor position from UITextview, i have implement the code in How to find a pixel-positon of a cursor in UITextView? post, the algorithm is based on algorithm in Pixel-Position of Cursor in UITextView . my problem is, i can't get the selectedRange.location value after keyboard appear in the 2nd time, cause it always tell that the value of location is 2147483647, which means not found. This is my implementation : -(void)getCursorPosition{ NSRange originalPosition = self.codeTextView.selectedRange; NSLog(@"original position : %d", self.codeTextView.selectedRange.location);