I have a kind of winforms applications, an VSTO Outlook addin. Within this application I am using a container that Outlook API provides and in this container you can embbed a Winforms usercontrol.
So now i want to use a WPF usercontrol in this application which I want to embbed within the container that Outlook API provides so what i have done is the following:
- Create a Winforms UserControl
- Whithin the Winforms UserControl created in step 1, I add an ElementHost container.
- Finally, within the ElementHost container I embed the WPF usercontrol throguh the Child property of the ElementHost.
The Winforms UserControl has below properties set:
- AutoScaleMode = dpi
- AutoSize = true
And the ElementHost has the AutoSize property set to true.
Now if you change the scale from the OS and start the application, the Outlook container is resizing perfectly according to the scale selected in the OS.
In the Winforms UserControl I have overrided the following method, so any scale operation goes through there and I can handle the scaling factor and then apply it to the Outlook container:
protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
{
base.ScaleControl(factor, specified);
// Record the running scale factor used
this.CurrentScaleFactor = new SizeF(
this.CurrentScaleFactor.Width * factor.Width,
this.CurrentScaleFactor.Height * factor.Height);
// Once I have the correct scale factor I apply it
// Do some stuff here
}
Above method is called every time my Winform application starts for first time. (It is ALWAYS called for first time).
Now I have a particular use case: With my Winform application already started and running, I change the scale from the OS, let's say, from 100% to 150%, so the WPF user control resizes and t causes also the ElementHost and Winforms user control to resize to fit its content (in this case the WPF user control) but what I notice is that the above method ScaleControl is not being fired for the Winforms user control.
So my question is: Why do the ScaleControl method is not being called when Winforms user control resizes? Also, as ScaleControl method is not being fired, is there any event in winforms that I can handle and which it is fired every time user explicitly changes the scale from the OS so I can then get the scale factor?
Note: As I cannot specify ore than 5 tags in the post, i must say that i am using .NET Framework 4.5 (Standard).