Thread: Annoying Icon Error in Treeview

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    38

    Annoying Icon Error in Treeview

    This is rubbish! I use these 2 lines to overcome the bug that makes icons not show in treeviews:


    Code:
    Application.EnableVisualStyles();
    Application.DoEvents();
    I put the lines just before I show the form - sometimes the icons show - other times not!! Why is it intermittant - why has this bug not been fixed properly by MS! Grrrrr!!!!

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Considering that you've only posted two lines (neither of which really help), I'll put on my psychic hat. Here's my guess at your code:
    Code:
    public class SomeApplication
    {
            Form1 frm = new Form1();
    
            //in some snippet of code...
            {
                    //...
                    Application.EnableVisualStyles();
                    Application.DoEvents();
                    frm.Show();
                    //...
            }
    }
    I'm really hoping this doesn't adequately fix your problem.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    38
    It doesnt sort my problem - yes I do show a form straight after the 2 lines of code - sorry for limiting it to just these 2 lines but the other code is a bit superfluous to the problem - as these 2 lines are often talked about as being able to 'solve' this particular problem.

    If you do know anything about this particular problem/bug with treeview icons and EnableVisualStyles() etc - I'm all ears.

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Code that you think is superfluous may not be. Case in point, it doesn't matter when you show your form; it matters when your form object is being created. If your form object is being created before the call to Application.EnableVisualStyles(), then there's your problem. The link also suggests that disabling VisualStyles will show the icons in either case, although that's not necessary if you fix your form object creation. Try something like this:
    Code:
    public class SomeApplication
    {
            Form1 frm;
    
            //in some snippet of code...
            {
                    //...
                    Application.EnableVisualStyles();
                    frm = new Form1();
                    Application.DoEvents();
                    frm.Show();
                    //...
            }
    }
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    38
    OK - Ill give it a try - thanks in the meantime.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    38
    Nope - the error came back - recompiled the project and the icons dissapeared from the treeview.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Icon Help
    By The Brain in forum Windows Programming
    Replies: 11
    Last Post: 04-05-2009, 04:06 PM
  2. Replies: 1
    Last Post: 08-04-2008, 05:34 PM
  3. Icon problem
    By mkyong in forum Windows Programming
    Replies: 0
    Last Post: 02-17-2003, 05:39 PM
  4. Icon? help!
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-16-2001, 06:21 PM
  5. icon in title bar?
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 12-12-2001, 06:43 PM