Hello,
I have an app that has a custom treeview which inherits the base
treeview class and I am having a problem with the way the treeview is
being redrawn. Each node in the treeview represents a folder, and
this problem began when I added the functionality to have a ghost
image of the folder when it is dragged and dropped to another location
in the treeview. My code to create the ghost image is as follows:
this.NodeToBeDeleted = (FolderNode)e.Item;
this.folderTreeView.NodeToBeDeleted = (FolderNode)e.Item;
string strItem = e.Item.ToString();
//this.folderTreeView.SelectedNode = this.NodeToBeDeleted;
// Reset image list used for drag image
this.imageListDrag.Images.Clear();
this.imageListDrag.ImageSize =
new Size(this.NodeToBeDeleted.Bounds.Size.Width
+ this.folderTreeView.Indent,
this.NodeToBeDeleted.Bounds.Height);
// Create new bitmap
// This bitmap will contain the tree node image to be dragged
Bitmap bmp = new Bitmap(this.NodeToBeDeleted.Bounds.Width
+ this.folderTreeView.Indent, this.NodeToBeDeleted.Bounds.Height);
// Get graphics from bitmap
Graphics gfx = Graphics.FromImage(bmp);
// Draw node icon into the bitmap
gfx.DrawImage(folderTreeViewImageList.Images[NodeToBeDeleted.ImageIndex],
0, 0);
// Draw node label into bitmap
gfx.DrawString(this.NodeToBeDeleted.Text,
this.folderTreeView.Font,
new SolidBrush(this.folderTreeView.ForeColor),
(float)this.folderTreeView.Indent, 1.0f);
Graphics Viewable = folderTreeView.CreateGraphics();
Viewable.DrawImageUnscaled(bmp, 0, 0);
// Add bitmap to imagelist
this.imageListDrag.Images.Add(bmp);
The FolderNode inherits from TreeNode. The problem is that when I
pick up a folder and move it around to be dropped in between other
folders in the treeview, each time another folder is highlighted as
the selected node under the dragged item, a trail of partially
highlighted folders remains from where I had previously dragged. This
is hard to explain, but it just looks like the highlighting for each
node from when it was the selected node is not completely removed. I
have tried several combinations of solutions for this but to no
avail. I did the following in my constructor:
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
//this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.UpdateStyles();
but the trail remains. Also, the trail was eliminated when I did
BeginUpdate() and EndUpdate() before highlighting each node under the
dragged item, but then the treeview flickers horribly as the dragged
item is moved around. So if there is some way to totally remove the
flicker the beginUpdate and endUpdate would be the answer. Can anyone
provide any insight into this? Thanks.