High DPI Support

160 views
Skip to first unread message

Terry Aney

unread,
Jul 28, 2016, 7:39:52 PM7/28/16
to Excel-DNA
I have some forms in my Excel addin that are looking pretty bad on high dpi monitors.  I found this link http://crsouza.com/2015/04/how-to-fix-blurry-windows-forms-windows-in-high-dpi-settings/ and was going to attempt to apply same thing but not sure where to put it in the lifecycle of the dna addin.  Any suggestions?

Thanks.

Govert van Drimmelen

unread,
Jul 29, 2016, 3:47:30 AM7/29/16
to exce...@googlegroups.com
Hi Terry,

I guess you can set it just before showing the form, or in the AutoOpen.

What have you tried?

-Govert

On 29 Jul 2016, at 01:42, Terry Aney <terry...@gmail.com> wrote:

I have some forms in my Excel addin that are looking pretty bad on high dpi monitors.  I found this link http://crsouza.com/2015/04/how-to-fix-blurry-windows-forms-windows-in-high-dpi-settings/ and was going to attempt to apply same thing but not sure where to put it in the lifecycle of the dna addin.  Any suggestions?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Terry Aney

unread,
Aug 12, 2016, 8:30:52 PM8/12/16
to Excel-DNA

Doesn't appear to work in AutoOpen...given the error message, doubt it'd work later in the workflow.  Also, moved call to SetCompatibleTextRenderingDefault chunk of code to be called before ComServer.DllRegister.Server() as well and same exception was thrown.  I'll dig around, but let me know if you have any other ideas.  Thanks.


Terry Aney

unread,
Aug 12, 2016, 8:32:44 PM8/12/16
to Excel-DNA
Below, somehow my image I posted is enclosed in the 'quoted text', so please expand that to see image if you want.


On Friday, July 29, 2016 at 1:47:30 AM UTC-6, Govert van Drimmelen wrote:

Govert van Drimmelen

unread,
Aug 14, 2016, 9:54:52 AM8/14/16
to exce...@googlegroups.com
Hi Terry,

This error might be due to the Excel-DNA SynchronizationContext window that is created before AutoOpen() runs.
One place that's a bit earlier than AutoOpen is the constructor for the class that implements IExcelAddIn.

Could you try the following?

public class ExcelAddIn : IExcelAddIn
{
    public ExcelAddIn()
    {
          // Call the EnableVisualStyles and SetCompatibleTextRendering here...
    }

    public void AutoOpen() { ... }
    public void AutoClose() { ... }

}

-Govert


From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of Terry Aney [terry...@gmail.com]
Sent: 13 August 2016 02:32 AM
To: Excel-DNA
Subject: Re: [ExcelDna] High DPI Support

Terry Aney

unread,
Aug 15, 2016, 6:53:43 PM8/15/16
to Excel-DNA
Thanks.  Well, no error, but didn't fix issue.  No idea what to do.  Shame that is so convoluted to make High DPI work.

Non DPI:



High DPI:

Govert van Drimmelen

unread,
Aug 16, 2016, 1:09:58 AM8/16/16
to exce...@googlegroups.com
Some of these setting might be per-process, so that Excel sets them, and your add-in won't have a chance to override.

Could you perhaps make a small project that I can experiment with?

-Govert
--

Terry Aney

unread,
Aug 17, 2016, 3:51:24 PM8/17/16
to Excel-DNA
Hopefully cleaned up enough.  You might have to clean up nugetpaths and postbuild, but code/project should be good.  Thanks for looking.
BTR.Extensibility.Excel.zip

Govert van Drimmelen

unread,
Aug 20, 2016, 5:51:38 PM8/20/16
to Excel-DNA
Hi Terry,

I built your project, and found the place where Excel-DNA initializes the WinForms, causing your call to SetCompatibleTextRenderingDefault to fail, even in the add-in constructor.
I'm not likely to change that, but one workaround would be to use reflection to call the internal Control.UseCompatibleTextRenderingDefault property.

However, I did test with an early call that succeeded, and it did not seem to make a different to the layout (which makes sense, since it just concerns the test rendering engine used by the WinForms controls).

I also make a small WinForms application and added your form. The same layout issues appear there.
So I think your High-DPI layout problems have nothing to do with Excel-DNA or Excel.
The best plan would be to sort out your form in a standalone application first.
If that works, and you still have issues in the Excel setting, I can have a look again.

Your issue did alert me to some layout anomalies in the IntelliSense too, which I've added an issue for.

-Govert
Reply all
Reply to author
Forward
0 new messages