dotnet windows forms:
JB,
Regarding your last question, I guess you're asking how to determine the
position of the mouse in the Textbox (so you can determine where to insert
the text.) Here's a snippet of code for you. The
GetTextPositionFromPoint() function returns the index into the TextBox.Text
that corresponds to the point passed in. HandleTextDragOver() does
something you may not want (it moves the text cursor to the point in the
textbox where the drop will take place), but it illustrates a use of the
method.
Tom Clement
Apptero, Inc.
public struct POINTL
{
public int x;
public int y;
public POINTL(Point pt) { x = pt.X; y = pt.Y; }
public POINTL(int x0, int y0) { x = x0; y = y0; }
public override string ToString() { return String.Format("POINTL
({0},{1})", x, y); }
}
[DllImport("user32.dll", EntryPoint="SendMessage", CharSet = CharSet.Auto)]
private static extern int SendMessageInt(IntPtr hWnd, UInt32 Msg, Int32
wParam, Int32 lParam);
[DllImport("User32.dll", EntryPoint = "SendMessage", CharSet =
CharSet.Auto)]
private static extern int SendMessageRefPoint(IntPtr hWnd, UInt32 Msg, int
wParam, ref POINTL point);
// Obtain the position in the text string from the specified
// window location. The position is in client coordinates of
// the textbox or richtextbox
public static int GetTextPositionFromPoint(TextBoxBase control, Point pt)
{
if (control is TextBox)
{
int result = SendMessageInt(control.Handle, EM_CHARFROMPOS, 0, pt.X +
(pt.Y * 0x10000));
return result & 0xFFFF;
}
else
{
POINTL pointStruct = new POINTL(pt.X, pt.Y);
return SendMessageRefPoint(control.Handle, EM_CHARFROMPOS, 0, ref
pointStruct);
}
}
public static void HandleTextDragOver(TextBoxBase txtBox, DragEventArgs e)
{
Point pt = txtBox.PointToClient(new Point(e.X, e.Y));
int iDropPos = API.GetTextPositionFromPoint(txtBox, pt);
txtBox.Focus();
txtBox.SelectionStart = iDropPos;
txtBox.SelectionLength = 0;
}
[quoted text, click to view] "JB" <jasonb@bellevue.com> wrote in message
news:JEp8b.1925$8g2.323@news1.central.cox.net...
> Also I need this text to go in the text box where the user drops it. How
do
> I determine this area....
>
> "JB" <jasonb@bellevue.com> wrote in message
> news:tlp8b.1921$8g2.19@news1.central.cox.net...
> > I can't seem to get exactly what I need. I have a list box as the
source,
> > and a text box as the target. I'm wanting to pick one listbox item,
> change
> > it's showing text slightly and alow a drop any where in the mulitlined
> text
> > box. I have the textbox set to allow drop, but all I ever get is the NO
> > mouse when I move over the textbox. What should my sequence of events
be
> > here?
> >
> > Jason
> >
> >
>
>