WinForms not Scaling Properly using Add-in Template for Inventor

WinForms not Scaling Properly using Add-in Template for Inventor

MercuryOptimizationSolutions
Participant Participant
336 Views
3 Replies
Message 1 of 4

WinForms not Scaling Properly using Add-in Template for Inventor

MercuryOptimizationSolutions
Participant
Participant

Hello all, 

Just looking for advice on how people are creating their apps for Inventor. I've run into this problem with scaling after creating a winform interface for my add-in using the Add-In template for 2022. I was able to set this up to compile as either an .exe or .dll with the same project by switching the project type. The .exe appears as it does in Visual Studio and when run on a display with 200% scaling, its sized properly if not a little pixelated. 

But if I run the form from the class library, the sizing is off on the controls where they overlap and the form implodes on the 200% scaling display. 

 

What I've been able to get so far is when I change the project to a forms application (.exe) 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 on the Revit forum, which Microsoft articles pointed to this fix:
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(False)

 

But this gives a System.InvalidOperationException: 'SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.' and since its the first item called in the Activate Sub(...) I think Inventor.exe is the first IWin32Window. 

 

Should I not be using Winforms? or what are others using for this? I read WPF fixes a lot of these issues. I'm never opposed to learning something new. 

P. Andrew White, P.Eng
Consultant Manufacturing Engineer | Architect of Optimization | Autodesk Developer
0 Likes
Accepted solutions (1)
337 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

You should be able to use Winforms and WPF. I always use WPF but that comes with its problems. (For example when you want to create dockable windows. As I explain in my blog post: "Creating a dockable window". )

Anyway, some time ago, someone had a similar problem. If I remember correctly, then you can set the "ForceDesignerDPIUnaware" to "true" in your project file. And that should solve the problem. More information can be found on this page: "Fix HDPI/scaling issues with Windows Forms Designer in Visual Studio"

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

marcin_otręba
Advisor
Advisor

Hi,

1. how is your form autoscale parameter set ? maybe change it to DPI- in standard it is font.

2. do you create any components by code ? if yes you should take into account DPI value specially if you set position or/and size of controls, because they will not be scaled automatically.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 4 of 4

MercuryOptimizationSolutions
Participant
Participant

That cleaned it up a lot, still didn't look perfect so I ended up replacing and rebuilding the main form in the WPF format but kept the original AD template, with my other 3 forms of the app set to "inherit", adding the WPF form and references changed those as well. It was odd behavior but worked. 

In the age of AI, using WPF and XAML to create a form for the first time wasn't terribly difficult. 

 

Thanks for the replies everyone!

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