Consistent display across different operating systems/graphic display

Add-in Express™ Support Service
That's what is more important than anything else

Consistent display across different operating systems/graphic display
 
Greg Donaldson




Posts: 7
Joined: 2015-04-14
I am struggling with getting a consistent display of my add in across different computers. For example - ones with the text size set to 125% makes it all wonky.

Do you have white papers or best practices to achieve the goal of an Add in that will display correctly across your users (public) landscape?

Thanks

Greg
Posted 12 May, 2015 07:30:01 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Greg,

We don't have such a white paper. Yet.

First off, you need to check the DPI:

        private static float dpi = 0;
        public static float DPI
        {
            get
            {
                if (dpi == 0)
                {
                    System.Windows.Forms.Form form = new System.Windows.Forms.Form();
                    Graphics g = form.CreateGraphics();
                    dpi = g.DpiX;
                    if (g != null) g.Dispose(); g = null;
                    form.Dispose(); form = null;
                }
                return dpi;
            }
        }


Then, you need to supply DPI-dependent images for the Ribbon controls. You do this in the OnRibbonBeforeCreate event of the add-in module.

If you show a dialog, you need to set AutoScaleMode=DPI.

If you use panes, you'll need to resize the pane and all controls on it manually (the code below is a raw sketch):


        public static int GetSizeFromDpiInt(int baseSize)
        {
            float result = (float)baseSize * ((float)DPI / (float)96);
            return Convert.ToInt32(result);
        }

        private static void relocateDPI(Control parentControl, bool firstControl)
        {
            if (parentControl == null) return;
            if (!firstControl)
            {
                parentControl.Location = new Point(GetSizeFromDpiInt(parentControl.Location.X), GetSizeFromDpiInt(parentControl.Location.Y));
                parentControl.Size = new Size(GetSizeFromDpiInt(parentControl.Width), GetSizeFromDpiInt(parentControl.Height));
            }

            foreach (Control child in parentControl.Controls)
                relocateDPI(child, false);
        }


These are the basics. The practice heavily depends on the actual controls used on your panes and dialogs. Our AbleBits.com guys (https://www.ablebits.com/) suggest that you only use the default Anchor (Top, Left), all other anchors misbehave.

Hope this helps.


Andrei Smolin
Add-in Express Team Leader
Posted 12 May, 2015 09:19:58 Top
Greg Donaldson




Posts: 7
Joined: 2015-04-14
Thank you for the code snippets. I should have been more specific - we have an Addin Express task pane and we are changing user controls on a panel on the task pane.

For your resizing code - what event are you firing this off? Also what settings do you have on your task pane for AutoScaleMode and AutoSizeMode?

Thanks

Greg
Posted 13 May, 2015 05:36:09 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Greg,

You call relocateDPI after InitializeComponents. You can set AutoScaleMode to DPI. As to AutoSizeMode, it can be set to any value; it just doesn't work in this case.


Andrei Smolin
Add-in Express Team Leader
Posted 13 May, 2015 06:31:27 Top