0
votes

I have created a VB.NET Class Library that exposes some COM Interop sub routines. These in turn show various forms that are contained within the Class Library. When the forms are shown from VB6 they do not inherit the visual styles of the operating system and act like VB6 controls.

I gather that this probably by design but is there some way to force/control visual styles manually in the .NET assembly? I would imagine that if I use a manifest in my VB6 app then everything will use the correct style but I would like to be able to control this myself if possible because we are using 3rd party controls in VB6 that do not require a manifest.

1
What's wrong with using a manifest? That's the standard way to go about this. You say that the third-party controls you're using in VB 6 don't require a manifest, but that's a far cry from "they break if we include a manifest". - Cody Gray
And my god, your entire app is custom controls? As in you're not using any standard Windows controls? I'll bet that's a user's worst nightmare. Pity on the fool who tries to navigate your app without a mouse. - Cody Gray
There is nothing wrong with a manifest per se but I don't want to use one if I don't have to. We are using the CodeJock control suite which has replacements for the standard button, checkbox, radiobutton controls, etc so it is really no different to using the normal controls, just that they inherit the styles without manifest. This is not the only reason we are using this control suite but they are bundled and we have paid for them so why not? - Matt Wilko
+1 It's reasonable to avoid the manifest. There's more to visual styles in a VB6 program than just the manifest - you may need special API code to avoid crashes, you might need to fiddle with your option buttons/frames/picture boxes... It's legitimate to seek to avoid all these problems with tweaks to the .Net code. - MarkJ

1 Answers

4
votes

I think the manifest is the way to do it, but first, you could always try this:

Add a reference to Windows.Forms and call these two methods in your assembly entry point:

    System.Windows.Forms.Application.EnableVisualStyles()
    System.Windows.Forms.Application.DoEvents()

Note: We call DoEvents() because there was framework bug which caused errors and badly drawn styles. I believe this has been fixed since, but just in case.