A friend met a winform problem, searched the Internet, did not find a solution to the problem,
It happened that I had met before and presented the solution here so that a friend who had encountered the problem would be helpful.
The problem is that when the virtual style is enabled, the icon for the set Teeview is gone, and the code is as follows:
Application.enablevisualstyles ();
The program generated in debug mode is not a problem, but generated in release mode is missing.
There is a method at the following address, but it does not necessarily solve the problem,
http://www.codeproject.com/KB/bugs/EnableVisualStylesBug.aspx?msg=984714
The method is called Application.enablevisualstyles (); Then add the code: application.doevents (); Online some friends said effective, I was also tried this method, no effect, do not know what reason, VS2005 out when there is this bug, VS2008 out when the problem is still.
Talk less, not because you do not know why not solve the problem it.
The method is super simple, first set the Treeview1.drawmode to Treeviewdrawmode.ownerdrawall, and then respond to the Drawnode event.
Treeview1.drawmode = Treeviewdrawmode.ownerdrawall;
Treeview1.drawnode + = new Drawtreenodeeventhandler (Treeview1_drawnode);
The event methods are:
void Treeview1_drawnode (object sender, Drawtreenodeeventargs e)
{
E.drawdefault = true;
if (e.node.bounds.x > && this.treeView1.ImageList! = null && This.treeView1.ImageList.Images.Count > E.node.imageindex)
{
Image img = This.treeview1.imagelist.images[e.node.imageindex];
if (img! = NULL)
{
E.graphics.drawimage (IMG, e.node.bounds.x-19, E.NODE.BOUNDS.Y);
}
}
}
Reference: http://www.cnblogs.com/roy/archive/2010/04/02/1703379.html
Resolving EnableVisualStyles Bugs