473,388 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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 )
}
Nov 16 '05 #1
2 8881
Hendrik,
If using RichTextBox take a look at
RichTextBox.GetCharIndexFromPosition method. This is what you are after, I
believe.
--
HTH
Stoitcho Goutsev (100) [C# MVP]

"Hendrik" <He*****@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
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 )
}

Nov 16 '05 #2
Hi

Many thanks
Can't believe I couldn't find that - works like a charm

"Stoitcho Goutsev (100) [C# MVP]" wrote:
Hendrik,
If using RichTextBox take a look at
RichTextBox.GetCharIndexFromPosition method. This is what you are after, I
believe.
--
HTH
Stoitcho Goutsev (100) [C# MVP]

"Hendrik" <He*****@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
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 )
}


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tom_ZC | last post by:
I'm writing a find and replace routine for a text editor I'm working on. The editor has a rich text box on the main form (frmMain). The find/replace form is modeled after the one in Word '97/2K. ...
1
by: MisterJ | last post by:
Here is the situation: I am attempting to reposition a rich text control within a frame in a running vb6 program. What I want to do is to click on the text box then drag it to a new position....
2
by: j van c | last post by:
I have a menubar on my main page. when clicking on a menu item I want to open an existing htm page at a certain position in my main page I use no frames. It should be replacing a div-section....
1
by: IkBenHet | last post by:
Hello, I found this script to create a simple rich text form (http://programmabilities.com/xml/index.php?id=17): <html> <head> <title>Rich Text Editor</title> </head> <body>
1
by: PC User | last post by:
I found this Rich Text Editor and I've been trying to recreate it in my own application. I've had trouble with the COMCTL.ImageListCtrl and the COMCTL.Toolbar to recreate the toolbar. And I've...
0
by: Al | last post by:
Hi I like to replace a character at the click of mouse. My main problem is when I click on the characters that need to be changing the richTextBox will scroll up make it very distracting. Is there...
2
by: jceddy | last post by:
Well, there is something here I'm working on, and I have a problem that has several possible solutions...none of which I can figure out how to implement. Basically, I am creating a rich text...
3
by: vtashore | last post by:
I downloaded Steve Leban's RTF2 control and it works as advertised. Good news! After reading reference material on the RTF standard codes, I have been able to write update queries to universally...
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.