0

I have a winforms application (well, it is an VSTO Outlook Add-in that runs within Outlook) in which I am using a toolbar and within this toolbar I embed a WPF user controls through the use of an ElementHost container.

My application fits well for different screen resolutions and/or scale factors if I restart it every time I change some display settings such as screen resolution and/or scale.

But now I have below two problems:

  1. It is not fitting correctly according to the screen resolution and/or scale selected from the OS without restarting it.
  2. It is not fitting correctly if I move my application from one monitor to another that has different screen resolution and/or scale.

In both cases I have rendering issues: some black lines are being drawn magically at the edge of the control, see below some screenshots (The toolbar that you see at the top which has the title "My Custom CTP" is an VSTO Outlook control that forces me to embed a winforms user control, so I do: Winforms user control <---> ElementHost <----> Wpf user control):

Horizontal black line

vertical black line

Bottom black line

Also my SVG images which are drawn using a Path and also all my TextBlocks appear blurry.

I have tried different attempts but without success.

ATTEMPT #1:

Using software rendering only as explained here. In my WPF user control, just after InitializeComponent in the constructor view, I perform below:

 public myWpfView()
 {
    InitializeComponent();

    if (ForceSoftwareRendering)
        RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
 }

 public bool ForceSoftwareRendering
 {
    get
    {
        int renderingTier = (System.Windows.Media.RenderCapability.Tier >> 16);
        return renderingTier == 0;
    }
 }

ATTEMPT #2: In my Wpf User Control constructor I subscribe to DisplaySettingsChanged event to detect display settings changes and in the handler I perform some invalidate actions and inmediatelly after that I update the layout. Again without success:

 public myWpfView()
 {
    InitializeComponent();

    Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
 }

 private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
 {
     this.VisualBitmapScalingMode = BitmapScalingMode.NearestNeighbor;
     this.VisualClearTypeHint = ClearTypeHint.Enabled;
     this.VisualEdgeMode = EdgeMode.Unspecified;
     this.VisualTextHintingMode = TextHintingMode.Auto;
     this.VisualTextRenderingMode = TextRenderingMode.ClearType;
     this.UseLayoutRounding = true;
     this.SnapsToDevicePixels = true;
     this.InvalidateVisual();
     this.InvalidateMeasure();
     this.InvalidateArrange();

     this.UpdateLayout();
 }

It looks like after changing screen resolution and/or scale, it is needed to update the layout for the wpf user control or something like that in order it readjusts without needing to restart it, so this is just what i tried to do in the SystemEvents_DisplaySettingsChanged event handler above indicate but without success. Maybe i am missing something, i don't know....

Additional Notes: I am using AutoScaleMode = dpi. Also tried font.

Willy
  • 9,848
  • 22
  • 141
  • 284

0 Answers0