This method searches for the character position at x,y.
Declaration
bool GetPosAtXY([In] int X, [In] int Y, [In] int Mode, out int CPPos);
Description
The Result is false if no text was found.
This code inserts the character X at the click position:
private void wpdllInt1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
IWPMemo Memo = wpdllInt1.CurrMemo;
int pos;
if (Memo.GetPosAtXY(e.X,e.Y,0,out pos))
{
int oldpos = Memo.TextCursor.CPPosition;
Memo.TextCursor.CPPosition = pos;
Memo.TextCursor.InputString("X",0);
Memo.TextCursor.CPPosition = oldpos;
Memo.ReformatAll(false,true);
}
}
Parameters |
X |
The horizontal position |
Y |
The vertical position |
Mode |
Selects the way the X and Y parameter is expected: 3 or -1: Don't use X and Y parameter. Use current mouse position instead. 0 : X and Y are client coordinates of the editor. If you use the method in OnMouseDown or OnMouseMove use this mode. 1 : X and Y are coordinates relative to upper left corner of edit control (including the toolbars) 2 : X and Y are screen coordinates (relative to desktop)
If bit 8 (value=256) is set in "Mode" the CurrPar interface will be updated to work with the found paragraph. In this case Pos will be the offset in this paragraph. |
out CPPos |
The absolute character position. |
For .NET Drag and Drop set the property AllowDrop to true.
Then you need two event handlers:
private void wpdllInt1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
wpdllInt1.TextCursor.InputText("Dropped text");
wpdllInt1.Reformat();
}
private void wpdllInt1_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
int pos;
if (wpdllInt1.Memo.GetPosAtXY(0,0,-1, out pos))
{
wpdllInt1.Memo.TextCursor.CPPosition= pos;
e.Effect=DragDropEffects.All;
} else e.Effect=DragDropEffects.None;
}