EnableVisualStyles and NotifyIcon bug

When Windows XP visual styles are enabled, if you use ShowDialog() on a form in response to an event raised by clicking on a NotifyIcon or a popup menu from a NotifyIcon, you get a SEHException when the form is closed.

Has anyone else noticed this  If so, how do you work around it


Answer this question

EnableVisualStyles and NotifyIcon bug

  • atul_v

    Where and how are you displaying the images

    Icons in an imagelist generally look OK in toolbars,tabcontrols,buttons and just about any control that takes an ImageList and ImageIndex.

    If you try to assign a 32bit image to a control such as label
        i.e. myLabel.Image = myImageList.Images(0)
    then that will usually end up with the alpha being flattened and shown as black or blue instead of semi transparent. This is an issue with Imagelist's and it should be fixed in VS2005.

    With a little more info on how and where you are assigning the images, we may be able to come up with a solution.

  • sibot13

    Ok, the images are now an embedded resource and I've got them to load into the form at run time (I put the code within the forms windows generated code as I dont have a form_load sub).   The icons load into the image list and onto the form but the shadows still appear as solid black lines   

    To make sure they loaded at the correct point, I removed (temporarily) the Application.DoEvents code and the icons still loaded into the imagelist.

    Could this be something to do with only having the standard version of VB.Net

    When I look at the icons (using windows explorer) within the new folder, the shadows appear as I expect, but when you open them in VS, the shadows show as the solid black lines

    Any ideas

    Thanks very much for all your help by the way, I really appreciate it. 




  • Frank Loizzi

    Because of the bug with ImageLists and EnableVisualStyles, I would say it is better to add the Icons as Embedded Resource and add them to the ImageList at runtime (in or after the Form_Load() method). If you do it this way, then DoEvents() is not needed after EnableVisualStyles().

  • ms44cn

    There is a known bug in the 1.1 framework where calling EnableVisualStyles breaks ImageLists etc. The workaround is to call DoEvents:

    public static void Main()
    {
        Application.EnableVisualStyles();
        Application.DoEvents();
        Application.Run(...);
    }

  • Charles G.-Marcil


    Public Shared Sub Main()
        Application.EnableVisualStyles() 
        Application.DoEvents() 
        Application.Run(New frmMain_Menu) 
    End Sub

  • double_detente

    Thanks - that fixes it.
  • sana234

    Basically I have assigned them to an imagelist at design time, and then onto the toolbar again at design time.  I am just starting to learn vb.net and many of the concepts are new to me and as a result, I am taking my time to make sure I do everything as I should do rather than what maybe the quickest route.
    Would it be better to build the image list at run time rather than design time and is this a practice I should be getting used to
    Thanks again for your help, it is much appreciated.
    Mark.

  • Paul Martin

    What page
    Are the icons stored in an ImageList with ColorDepth set to Depth32Bit

  • mcclurgj

    I've been having problems with my images not showing in TreeViews, ListViews, and ToolBars and I couldn't figure it out. Thanks for posting this!
  • PedroAntonio

    I have all the icons stored within an image list and the colour depth is set to 32Bit.  Weird thing is that the icons work fine when they are on your desktop and the shadows are present but as soon as you put them into your project (within the image list), the opacity of the shadows changes so that the shadows appear as a solid black colour.

  • Recycled Gardens

    I've never embedded a resource before.  Can you point me to any places where I could find the answer or even better, if you could point me in the right direction it would help!
  • bronce32

    Iin your projects solution explorer, right click your project name and select add new folder.
    Select the new folder and add the icons to it.
    Set the BuildAction property of each icon to Embedded Resource.
    Name the icons according to the index at which you want them to appear. (i.e. image01.ico , image02.ico, image03.ico)
    Add the following code to Form_Load()

    Dim assy As System.Reflection.Assembly = Me.GetType.Assembly
    For Each resourceName As String In assy.GetManifestResourceNames
        If resourceName.EndsWith("ico") Then
            ImageList1.Images.Add(Image.FromStream(assy.GetManifestResourceStream(resourceName)))
        End If
    Next

    Note that you can set the imageindex at designtime even though the imagelist contains no images.

    It was not necessary to place the icons in a folder, but it helps to keep the solution explorer tidy.

  • SRavi

    Thanks for that, one other question for you... Now the icons are showing on the page but if they have shadows on them, the shadows appear as solid colour rather than partially transparent.  Any clues
  • Syva

    Now I'm probably being a little bit think here but where do I put this code   At the moment I have my app pointing to Module1 to kick it off.  I have the code below to kick it all off but I have tried to rebuild the solution and the project but the styles still dont seem to update.  I also had a situation where I was debugging the app but code was being executed that wasn't 
    even there   I have tried adding the suggested code within Module1 but to no avail, it doesn't like the syntax.

        Public Sub Main()
            Application.EnableVisualStyles()
            Application.DoEvents()
            Application.Run(frmMain_Menu)
        End Sub

    Help!!!!!!

  • EnableVisualStyles and NotifyIcon bug