0

I have an VSTO Outlook Add-in which shows a custom task pane (ctp). This ctp embeds a usercontrol which in turn contains an elementhost. The elementhost hosts an WPF user control.

At Add-in startup I create the ctp and I set it a fixed height, e.g. 120 points. I have noticed that depending on the screen resolution the ctp height gets smaller or bigger.

So I would like to know if there is a way to set the ctp height according to the current screen resolution so it does not get smaller or bigger.

For example some formula:

ctp.Height = Default_Height * Y_Scaling_Factor

I have tried setting the autoscalemode to font and dpi and it does not work.

Willy
  • 9,848
  • 22
  • 141
  • 284

1 Answers1

1

You need to set the AutoScaleMode property to None if you don't want to get the container scaled according to the screen resolution.

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.

Also you may take a look at the AutoSize and AutoSizeMode properties that resize the form according to the setting of AutoSizeMode.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • What i want is that the controls in the usercontrol that is embedded in te ctp to be always visible and not cut. So in my case, according to your answer, i have two options as i understand: 1) Set AutoScaleMode to None (then i guess that if i set a fixed height for ctp it will be always the same and respected regardless the screen resolution, right? So my controls in it will maintain their size and not cut) 2) Set Autosize to true and AutoSizeMode to GrowAndShrink (in this case do AutoScaleMode need to be set to None?) What is the best in my scenario, 1 or 2? – Willy Feb 05 '23 at 22:14
  • Setting AutoScaleMode to None is not working even if i set Autosize to true and AutoSizeMode to GrowAndShrink. Also I have checked using AutoScaleMode to Font and Dpi combined with AutoSize to true and AutoSizeMode to GrowAndShrink. In all cases is not working. It work only if i set scale to 100% in Operating System, otherwise if I set a scale in OS greater than 100%, e.g. 125% or 150% then it does not work. – Willy Feb 07 '23 at 18:52
  • I'd suggest describing what exactly you are changing in the OS and what you expect to get as an end result. – Eugene Astafiev Feb 07 '23 at 19:21
  • In the Operating System (Windows) from display settings I am changing screen resolution and scale. The result I expect is that independently of these parameters, i want that the custom task pane resize its height to fit its content and not cut the controls in the wpf usercontrol. – Willy Feb 07 '23 at 21:56
  • ...so i am trying to get the scale factor of the system and apply it to the custom task pane height (by doing ctp height * scaleFactor) every time the user changes the screen resolution and scale from the Operating system. How can I do this? If i do not do this then the ctp is not being resizing to fit its content and hence that controls (images, buttons, textblocks, etc.within wpf user control) are being cut and not displayed correctly every time the user changes screen resolution and scale in his/her OS. – Willy Feb 08 '23 at 08:34