locked
Make a VB6 ocx use XP styles on a VB.NET form RRS feed

  • Question

  • Hi!
    I have a VB6 ocx which was used in a VB6 program which made use of XP styles using a manifest and InitCommonControls.
    While the program itself was migrated to VB.NET 2.0 the ocx has to be used for the time being.
    Is it possible to modify the ocx or the VB.NET 2.0 assembly so that the ocx will look XP style? I tried altering the manifest of the VB.NET assembly and calling InitCommonControls from inside the ocx and the VB.NET assembly but it didn't work.
    VB6 ocx controls will (sometimes at least) look right in the Forms Designer but revert to the old VB6 style at runtime.
    Is there any way to fix this?
    Thanks,
    Chris.

    Tuesday, February 10, 2009 12:29 AM

Answers

  • Hi Chris,

    I've also made an VB6 OCX with several basic controls (button, checkbox, textbox, combo) and put it on a simple WinForm with one .NET Button control on it.

    After adding a MyApp.exe.manifest (My exe name is myapp.exe, I believe you know the rule for manifest file naming), everything on the form show up in correct visual style at runtime.

    Since I'm not sitting beside you for trouble shooting, I can only make some guesses:

    * The manifest you're using for your .NET EXE is wrong in some way. You can verify this by:
    1. Uncheck "Enable XP Visual Styles".
    2. Re-compile
    3. Run Application

    If your manifest file is okay, then by uncheck "Enable XP Visual Styles", your .NET controls should still have a visual style look. If not, the problem is the manifest file.

    * Or... your project somehow has a manifest embeded. This is by default in VS2008, in VS2005, we have to make a win32 res file to achieve that. If that is the case, the embeded manifest wins, so we'll have to make changes to the embeded one.

    You can also try make a simple winform app to test with your simple vb6 ocx.

    Let's see what happens.

    Thanks,

    Jie
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by minardifan666 Friday, February 13, 2009 1:46 PM
    Friday, February 13, 2009 7:39 AM
    Moderator

All replies

  • Hi Chris,

    I'd like to know which version of Visual Studio are you using. Because VS2005 and VS2008 both support .NET 2.0 VB application development, but the solutions to your problem are different on these two platforms.

    Besides, there is no need to call InitCommonControls in neither your OCX code nor VB.NET code.

    Calling InitCommonControls before UI shows up is a way to make sure the ComCtl32.dll will be loaded in VB6 exe code.

    In your situation (VB.NET), just check the "Enable XP visual styles" in project properties will do it.

    Please let me know the version of VS you're using so I can give you more specific help on it.

    Thanks,

    Jie
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, February 12, 2009 11:07 AM
    Moderator
  • Hi Jie, thanks for you help.
    I'm using VS2005 and I already have the Windows Application Framework enabled and the "Enable XP visual styles" checked in my project properties. All VB.NET controls show XP styles, just the VB6 OCX doesn't at runtime. In the Windows forms designer the VB6 OCX however will show the XP styles too. For testing purposes I made a simpe VB6 ocx consisting of a single button, which shows the same behaviour.
     Is there anything more I have to do to make the styles work?

    Thanks,
    Chris.

    Thursday, February 12, 2009 9:06 PM
  • Hi Chris,

    I've also made an VB6 OCX with several basic controls (button, checkbox, textbox, combo) and put it on a simple WinForm with one .NET Button control on it.

    After adding a MyApp.exe.manifest (My exe name is myapp.exe, I believe you know the rule for manifest file naming), everything on the form show up in correct visual style at runtime.

    Since I'm not sitting beside you for trouble shooting, I can only make some guesses:

    * The manifest you're using for your .NET EXE is wrong in some way. You can verify this by:
    1. Uncheck "Enable XP Visual Styles".
    2. Re-compile
    3. Run Application

    If your manifest file is okay, then by uncheck "Enable XP Visual Styles", your .NET controls should still have a visual style look. If not, the problem is the manifest file.

    * Or... your project somehow has a manifest embeded. This is by default in VS2008, in VS2005, we have to make a win32 res file to achieve that. If that is the case, the embeded manifest wins, so we'll have to make changes to the embeded one.

    You can also try make a simple winform app to test with your simple vb6 ocx.

    Let's see what happens.

    Thanks,

    Jie
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by minardifan666 Friday, February 13, 2009 1:46 PM
    Friday, February 13, 2009 7:39 AM
    Moderator
  • Great!
    It works now. I made an new VB.NET project and created a manifest, and it works now. Somehow I must have screwed up the manifest the last time around.
    Thank you for your help!

    Chris.

    Friday, February 13, 2009 1:46 PM