Resolving EnableVisualStyles Bugs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.