I'm trying to implement a custom TreeView that shows a ghost image while
dragging. But the form I'm using is different from the sample code found
here: http://www.codeproject.com/cs/miscct...ewDragDrop.asp
The problem is I can't get the proper coordinates required when dragging
begins. I have two tree views in a panel with a splitter, and the panel is
on a TabControl.
The sample code just has a simple form with the treeview control filling the
form.
Here is how the sample gets coordinates:
Point pt = PointToClient(C ontrol.MousePos ition);
In my implementation, that provides incorrect coordinates.
I have a splitter (to make one tree smaller and one larger) which means the
tree on the left is docked LEFT and the one on the right is docked FILL.
Does this mean both TreeView's coordinates start at the left edge of the
panel?
I've tried this:
Point pt = PointToClient(F orm.MousePositi on);
but no luck...
Below is more complete code.
What is the best way to get the coordinates of the node which is about to be
dragged so I can get a ghost image?
Thanks in advance.
private void tree_ItemDrag(o bject sender, ItemDragEventAr gs e)
{
//PROBLEM: not getting ghost image, probably due to incorrect mouse
coordinates
TreeView tree = (TreeView)sende r;
dragNode = (TreeNode)e.Ite m;
tree.SelectedNo de = dragNode;
imageListDrag.I mages.Clear();
imageListDrag.I mageSize = new Size(dragNode.B ounds.Size.Widt h +
tree.Indent, dragNode.Bounds .Height);
Bitmap bmp = new Bitmap(dragNode .Bounds.Width + tree.Indent,
dragNode.Bounds .Height);
Graphics gfx = Graphics.FromIm age(bmp);
gfx.DrawImage(i mageListConfigu ration.Images[0], 0, 0);
// optional: Draw node label into bitmap
//gfx.DrawString( "CFG", tree.Font, new SolidBrush(tree .ForeColor),
(float)tree.Ind ent, 1.0f);
imageListDrag.I mages.Add(bmp);
//imageListDrag.I mages.Add(Image Helper.getImage (folder));
//Point p = tree.PointToCli ent(Control.Mou sePosition);
//!!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!
Point p = tree.PointToCli ent(Form.MouseP osition); //does not help
int dx = p.X + tree.Indent - dragNode.Bounds .Left;
int dy = p.Y - dragNode.Bounds .Top;
if (TreeHelper.Ima geList_BeginDra g(imageListDrag .Handle, 0, dx, dy))
{
tree.DoDragDrop (bmp, DragDropEffects .Move);
TreeHelper.Imag eList_EndDrag() ;
}
}