Add-in window form scaling incorrectly

Add-in window form scaling incorrectly

TA.Fehr
Advocate Advocate
790 Views
6 Replies
Message 1 of 7

Add-in window form scaling incorrectly

TA.Fehr
Advocate
Advocate

I've written a number of add-ins and have had no issue with the form scaling correctly.

However, in my most recent submission to the app store, the Autodesk tester noticed the window would do strange things upon loading (see screencast)

 

Yet when I use the installer provided by the tester, it worked as expected (see attached video)

 

It's very hard to solve because I can't t replicate the problem.
I've tried disabling the "autoscale" in the designer but to no avail.

 

If any are willing to try, let me know if you see the same issues. (See attached installer from Autodesk)

 

0 Likes
791 Views
6 Replies
Replies (6)
Message 2 of 7

TA.Fehr
Advocate
Advocate

I did another test with an Autodesk employee who manages the app-store and he noted that the app didn't scale correctly on his computer and his resolution was 1920x1080 with 125% magnification. As my monitor only goes up to 1680x1050 I couldn't replicate this. Is it possible this is an issue directly related to the monitor scaling? And if so, is there a setting within Visual Studio that can address this?

Any help is greatly appreciated.

0 Likes
Message 3 of 7

f_opti
Explorer
Explorer

Did you ever figure this out? I've been at it the last 12 hours still to no avail, tried everything and every possible combination. I setup my app to compile as an .exe and .dll by changing the Application Type. SOooooo, if I run the same project compiled to a .exe , the scaling is correct on all monitors; if i switch it to a class library (load it into inventor, ...., ... ) the main form opens via:

Dim frm As System.Windows.Forms.Form
frm = New frmMain
frm.Show()

 

And on this, the scaling is way off with controls overlapping and not equally spaced. 

 

 

Currently I wrote my installer to copy the .exe to program files and then start the .exe from the button on the ribbon if it can find it, otherwise it will initialize a new form. I programmed it so basically if the program can't link to Inventor thru the addinsiteobject it will resort to late binding. 

 

Here's the same forms side by side, left image via .dll and the other is from the .exe:

f_opti_0-1728477099413.png

 

0 Likes
Message 4 of 7

TA.Fehr
Advocate
Advocate

I was able to resolve it. I had a similar situation to you so hopefully you can find this helpful.


I had to go into each of my forms an ensure AutoScaleMode was set to DPI.
I also added this line to each of the initialize subs:

        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
        Me.AutoScaleDimensions = New System.Drawing.SizeF(CSng(CreateGraphics().DpiX), CSng(CreateGraphics().DpiY))

I don't know if that was necessary, but i haven't noticed it causing any problems.


Another thing was I needed to go through each of my forms and ensure it was designed in a way that would permit automatic resizing. (IE using TableLayoutPanels with rows/columns set to autosize, and ensuring each control was docked correctly).

This was by far the biggest issue, but also the biggest pain in the neck to get right.


There were still some controls that refused to play nice (tab control was a big one) so I had to programmatically manage it.

Message 5 of 7

MercuryOptimizationSolutions
Participant
Participant

Yes sir, found in the Initialize() function for the form was a rogue

Me.AutoScaleDimensions = New System.Drawing.SizeF(96.0 , 96.0)

which was undoing everything I was testing on it. 

 

Still didn't scale perfectly but its close enough that the new scale alignment and view look intentional. I have a laptop at 200% scaling I'm going to try out tomorrow. I'll write back if it doesn't work.

 

Thanks so much for the response!

P. Andrew White, P.Eng
Consultant Manufacturing Engineer | Architect of Optimization | Autodesk Developer
0 Likes
Message 6 of 7

Tried it on the 200% scaling and the form imploded, found out a few things. The class library doesn't have the "Enable XP Visual Styles" (which is funny to be talking about in 2024 haha, perhaps a sign I'm off track?) which you would fix with:

System.Windows.Forms.Application.EnableVisualStyles()

 

Went I change the project to a forms application and disable "XP Visual Styles" it appears the same way it does when I compile it into the .dll plug in and launch it from Inventor. Tried everything but can't seem to get the .dll version to use those visual styles.

 

I also found the same problem devs were having in Revit, which Microsoft articles pointed to this:
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(False)

 

But this results in:

 

System.InvalidOperationException: 'SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.'

 

I placed it in the Activate(...) Sub to be the first thing called which leads me to believe the first IWin32Window object might be Inventor itself?

 

Read that WPF inherently fixes a lot of these DPI and scaling issues. 

 

P. Andrew White, P.Eng
Consultant Manufacturing Engineer | Architect of Optimization | Autodesk Developer
0 Likes
Message 7 of 7

TA.Fehr
Advocate
Advocate

I had also heard that moving to WPF resolves a great deal of scaling problems. My issue was that everything had already been designed and it was too much effort to re-do it all.
Have you arranged your forms with tablelayoutpanels? Have each control in its own cell, set the dock to "fill" and ensure the row/column modes are set to "autosize". And make sure the form itself is set to "autosize = true".

It's not as hard as recreating with WPF, so it might be an easier solution for you.
That's the only thing I can think of for your case unfortunately.

0 Likes