1. TextBox: get text at/around mouse position
In a TextBox, I'm using a MouseMove event to track the cursor position.
I want to get able to tell what text the current cursor position is at so I
can set the SelectionStart to that position.
private void textBox1_MouseMove(object sender, MouseEventArgs e)
{
Point p = textBox1.PointToClient(new Point(e.X, e.Y));
/* now what to do I do with Point to figure out the character
position in the text box??? */
SelectionStart = ????
}
The only solution I can figure out so far is to call the Windows API
user.dll and send a click event. This effectively sets the SelectionStart
position. Is there a way to send a click all within .NET and not use the
API?
Better yet would just to be able to determine directly the current character
position in the (multi-line) TextBox.
2. Mouse Position While Dragging and Dropping - CSharp/C#
3. Capture mouse position during resizing header of ListView ?
Is it possible to obtain without WinAPi ? Gawel
4. mouse position with respect to screen - CSharp/C#
5. inserting text at mouse position in text or rich edit box
Hi
I have searched extensively for help on inserting text at the position of
the mouse pointer in a text box as the final step of drag and drop process
What I have come with is listed below - the problem is that the SendMessage
function doesn't seem to perform the expected operation of moving the caret
to position in the textbox where the mouse is pointing to. (can be text or
richtext box either is good - sample code is based of attemp with richtext)
I would be greatfull if someone could perhaps assist me by pointing out my
error
Thanks
my attempt:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int
lParam);
//DragOver event of the RichTextBox
private void txtMDXExpression_DragOver(object sender,
System.Windows.Forms.DragEventArgs e)
{
const int EM_SETSEL = 0x0400 + 177;
txtMDXExpression.Focus();
txtMDXExpression.SelectionLength = 0;
//make a point object from argument parameters
Point mouseP = new Point(e.X,e.Y);
//get position of mouse within textbox
Point scrPt = txtMDXExpression.PointToClient(mouseP);
SendMessage(txtMDXExpression.Handle, EM_SETSEL, scrPt.X, scrPt.X )
}
6. Setting Mouse Position - CSharp/C#
7. Mouse position without events
Hi, I need to detect mouse position without events. In some places in code I need to get position but mouse didn't do anything(click,move...). Thanks