We’re converting our fairly large VB6 project to VB.NET here at work. The eventual target is a re-write in C# but the first phase of that is to move all the code to VB.NET using the VB conversion wizard so that we can start refactoring bits and pieces using C# without relying on interop. Interop scares me. I’m not sure why.
The conversion wizard created a zillion bugs which we expected. We’ve had to hand tweak a LOT of code to even get the project compiling. But now we are getting into the weird stuff. Specifically there is a lot of strange stuff surrounding the UI. I thought I’d document it here for several reasons.
- It annoys me. I like ranting
- Someone else might have this problem and this might save them some time
- Sometimes people read my posts and explain why this stuff works the way it does. I’m very curious.
Issue #1 – Arial?!
After running the conversion we noticed a lot of the text on the dialogs was really ugly. Letters would butt together in some places and have goofy gaps in others. It turns out the VB.NET conversion wizard takes the default 8pt MS Sans Serif font from VB6 and turns it to a 8pt Arial. This is weird because the default font in .NET is 8pt MS Sans Serif so the conversion tool goes through and hard codes Arial on pretty much every control in the project.
Luckily this was fairly easy to fix. A simple regular expression search and replace across all the .Designer.vb files to delete lines with ‘.Font = “Arial….”‘ in them.
Issue #2 – The Widening Fonts
Another VERY annoying issue was that in the VB.NET designer we would create a label or checkbox with some text on it and size it accordingly. When we ran the project the font width would change ever so slightly and sometimes cause words to be wrapped. The result was words were pretty much randomly being cut off the end of our controls.
We could have just made the controls a tad wider but that’s not a very good fix. We have a lot of controls and having to run the program just to check your control size is stupid.
I spent a bunch of time making simplified projects in VB6, porting them to .NET and comparing them to projects (file level diffing) written from scratch in .NET and eventually found what was causing this.
The following image is an overlay of a screenshot of the form in the VB.NET Designer and a screenshot of the same form at run-time. Notice how the font is slightly wider in the run-time version.

It turns out the resolution for this is to check off the “Enable application framework” button in the project properties. This adds a new class “Application.Designer.vb” that contains a very small amount of code and none of that code looks like it should have anything to do with font sizes but it does.
How does that make any sense?
Issue #3 – The stubborn Flexgrid
Another issue was we have a form with a flexgrid on it. This flexgrid is an old ActiveX version wrapped in .NET code. Not ideal but should do the job until we can replace with a native .NET control.
Unfortunately on this form we would make changes to the size of the control. Save. Reload the file and it would be right back to where it was.
We tried all sorts of things. We confirmed that the .Designer.vb file did reflect the changes in control size but as soon as you reloaded the form the control would be back to where it was.
It turns out there is a block of stuff in the form’s resX file called “OcxState”. This is a big blob of base-64 encoded data. No idea what’s really in there. As an experiment I just tried deleting that data and reloading the form and all of a sudden it works. The next time we saved the form it rewrote a blob of “OcxState” to the resX file but this time it did not interfere with the control sizing made in the designer.
I’m not sure what data was in that OcxState but hopefully we aren’t losing anything by deleting it. We haven’t come up with any other way around this.
Issue #4 – The resizing Forms
All our MDI child forms were having problems. These child forms are usually resizable and we’re taking advantage of the nifty control anchoring built into Windows Forms. Unfortunately, every time we opened one of these child forms they would change their form size and mess up the anchoring (pretty much the size of the form was changed before the anchors were enabled).
It turns out the the VB conversion wizard was setting the “StartPosition” property of all our forms to “WindowsDefaultBoundary” which for MDI children means their size gets screwed up. When we turned it back to the default value of “WindowsDefaultLocation” things behaved normally. Thanks Microsoft!
Anyways that’s it so far. I’m sure there will be more.