I have a physical object in the shape of a circle that measures 3 inches in diameter. My application transposes this circle shape onto the screen so the user can visually check off what they see into the application from the circle object. The problem I have is that I need the circle object to be 3 inches in diameter and appear the same size on all monitor types and all resolutions.
Is this possible? I am using WPF and have something like this already:
<Window.Resources>
<behaviors:InchesToIndependentUnitsConverter x:Key="InchesToDeviceIndependentUnits" />
</Window.Resources>
...
<Ellipse x:Name="MyCircle" Height="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth}" Width="{Binding CircleDiameter, Converter={StaticResource InchesToDeviceIndependentUnits}}" Margin="0,0,0,20" Fill="White" BorderBrush="Black" BorderThickness="1" VerticalAlignment="Top" HorizontalAlignment="Center"></Ellipse>
...
My inches to DIU converter looks something like this:
public class InchesToIndependentUnitsConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
int diameterDIU = 0;
if ((double)value > 0)
{
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{
diameterDIU = (int)((g.DpiX / 96) * value);
}
}
return diameterDIU;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
throw new NotImplementedException();
}
As expected, this works very well on a say a 1920 x 1200 res monitor, but when I start to get lower, naturally everything looks bigger. I need the diameter of my <Ellipse>
tag to always be 3 inches no matter what resolution the person's monitor is.
Thanks!