GetPosAtXY Method

[Top]  [Chapter]  [Previous]  [Next]

This method searches for the character position at x,y.


bool GetPosAtXY([In] int X, [In] int Y, [In] int Mode, out int CPPos);


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.CPPosition = oldpos;







The horizontal position


The vertical position


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");




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;


   }  else e.Effect=DragDropEffects.None;


[idh_iwpmemo_getposatxy.htm]    Copyright © 2007 by WPCubed GmbH