none
Set Custom Task Pane width for high DPI display in Outlook 2013 RRS feed

  • Question

  • I'm having an issue on higher DPI displays setting the custom task pane width, it's half as wide than it is on a 96 dpi display.

    Note that my Winforms usercontrol within the pane has the correct width when set in pixels, but doing the same on the Outlook custom task pane results in it being half as wide. I also can't find a way to determine the current dpi or scaling to do this manually as Graphics class reports 96 DPI and 1440x900 when the display is actually 2880x1800 scaled.

    Monday, April 13, 2015 9:31 PM

All replies

  • Did you check out the AutoScaleMode property of the user control?

    The AutoScaleMode property specifies the current automatic scaling mode of this control. Scaling by Font is useful if you want to have a control or form stretch or shrink according to the size of the fonts in the operating system, and should be used when the absolute size of the control or form does not matter. Scaling by Dpi is useful when you want to size a control or form relative to the screen. For example, you may want to use dots per inch (DPI) scaling on a control displaying a chart or other graphic so that it always occupies a certain percentage of the screen. 

    For more information about automatic scaling, see Automatic Scaling in Windows Forms.

    Tuesday, April 14, 2015 6:31 AM
  • As previously stated in my question, my Winforms controls (user control) renders perfectly. The custom task pane owned by outlook/office is not a winforms control and has no such AutoScaleMode. 
    Wednesday, April 15, 2015 2:47 PM
  • The custom task pane owned by outlook/office is not a winforms control 

    Where do you place your winforms controls then then?

    Take a look at the Problem with usercontrol scaling when added at run-time in .Net, WinForms page where a similar issue is described. 

    It is not clear where you get an instance of the Graphics class in the code. But you can use the CreateGraphics method of your Windows forms controls that were rendered correctly to get a valid results. 

    Wednesday, April 15, 2015 3:10 PM
  • The custom task pane has a property on it called Control and it accepts a Winforms user control, the inner contents (the user control) width renders fine, but the container (Outlook custom task pane) renders at 1/2 width in my case when set to the same width.

    I think the confusion is that the Custom task pane itself is not a Winforms control, it's an office control that allows you to put a Winforms control inside of it. The contents inside (winforms) is NOT what I'm having an issue with, its width renders perfectly.

    As you can see in the image, the containers (Custom Task Pane) width when set to the same width as the Winform control seems to actually be 1/2 width. 

    It doesn't matter what's inside the task pane, we could leave it completely empty for the purpose of this problem.

    Wednesday, April 15, 2015 4:05 PM
  • Outlook doesn't resize task panes, the add-in developer is responsible for such things.
    Wednesday, April 15, 2015 9:42 PM
  • Obviously.

    We just had a conversation about how Outlook doesn't take high DPI displays into account when setting widths and now you are assuming that I didn't know the developer had to resize the task pane?

    Thanks for your help, but you're just spinning my wheels. I'll go to Stackoverflow moving forward.

    Wednesday, April 15, 2015 10:04 PM
  • Stackoverflow is not a panacea. Anyway, I'd suggest composing your questions properly - what exactly you are looking for...  at least be more specific and describe issues in depth. It is not clear what you are doing in the code.


    but doing the same on the Outlook custom task pane results in it being half as wide.

    What code did you use for doing "the same"? 

    I also can't find a way to determine the current dpi or scaling to do this manually as Graphics class reports 96 DPI 

    Where did you get the Graphics object? 

    In general, could you be more specific?

     
    Wednesday, April 15, 2015 10:28 PM
  • Look what I created by using StackOverflow

            public static float GetScalingFactor(Visual visual)
            {
                var source = PresentationSource.FromVisual(visual);
               
                if (source != null)
                {
                    //returns 1.25 for 125%
                    return (float)source.CompositionTarget.TransformToDevice.M22;
                }
    
                return 0;
            }

    Then you just set CustomTaskPane.Width = someWidth * GetScalingFactor(...)

    Thursday, April 23, 2015 10:44 PM