You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.5 KiB
C#
137 lines
4.5 KiB
C#
// ***********************************************************************
|
|
// Assembly : Construction
|
|
// Author : flythink
|
|
// Created : 07-01-2020
|
|
//
|
|
// Last Modified By : flythink
|
|
// Last Modified On : 09-01-2020
|
|
// ***********************************************************************
|
|
// <copyright file="HightDpiHelper.cs" company="jindongfang">
|
|
// Copyright (c) jindongfang. All rights reserved.
|
|
// </copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
namespace WellWorkDataUI
|
|
{
|
|
using System;
|
|
using System.Drawing;
|
|
|
|
/// <summary>
|
|
/// 高分辨率处理类
|
|
/// </summary>
|
|
public static class HightDpiHelper
|
|
{
|
|
/// <summary>
|
|
/// Gets the dpi scale factor.
|
|
/// </summary>
|
|
/// <value>The dpi scale factor.</value>
|
|
public static float DpiScaleFactor => DevExpress.Skins.DpiProvider.Default.DpiScaleFactor;
|
|
|
|
/// <summary>
|
|
/// Scales the center rectangle.
|
|
/// </summary>
|
|
/// <param name="rectangle">The rectangle.</param>
|
|
/// <returns>Rectangle.</returns>
|
|
public static Rectangle ScaleCenterRectangle(Rectangle rectangle)
|
|
{
|
|
double centerX = rectangle.Left + (rectangle.Width / 2.0);
|
|
double centerY = rectangle.Top + (rectangle.Height / 2.0);
|
|
|
|
Size newSize = ScaleSize(rectangle.Size);
|
|
|
|
return new Rectangle(
|
|
Convert.ToInt32(centerX - (newSize.Width / 2)),
|
|
Convert.ToInt32(centerY - (newSize.Height / 2)),
|
|
newSize.Width,
|
|
newSize.Height);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Scales the font.
|
|
/// </summary>
|
|
/// <param name="font">The font.</param>
|
|
/// <returns>Font.</returns>
|
|
public static Font ScaleFont(Font font)
|
|
{
|
|
if (DpiScaleFactor != 1f)
|
|
{
|
|
return new Font(font.FontFamily, ScaleHeight(font.SizeInPoints - 0.25f));
|
|
}
|
|
|
|
return font;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Scales the height.
|
|
/// </summary>
|
|
/// <param name="h">The h.</param>
|
|
/// <returns>System.Int32.</returns>
|
|
public static int ScaleHeight(int h) => Convert.ToInt32(h * DpiScaleFactor);
|
|
|
|
/// <summary>
|
|
/// Scales the height.
|
|
/// </summary>
|
|
/// <param name="h">The h.</param>
|
|
/// <returns>System.Single.</returns>
|
|
public static float ScaleHeight(float h) => Convert.ToSingle(h * DpiScaleFactor);
|
|
|
|
/// <summary>
|
|
/// Scales the rectangle.
|
|
/// </summary>
|
|
/// <param name="rectangle">The rectangle.</param>
|
|
/// <returns>Rectangle.</returns>
|
|
public static Rectangle ScaleRectangle(Rectangle rectangle)
|
|
{
|
|
return new Rectangle(rectangle.Location, ScaleSize(rectangle.Size));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Scales the size.
|
|
/// </summary>
|
|
/// <param name="size">The size.</param>
|
|
/// <returns>Size.</returns>
|
|
public static Size ScaleSize(Size size)
|
|
{
|
|
return new Size(ScaleWidth(size.Width), ScaleHeight(size.Height));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Scales the size.
|
|
/// </summary>
|
|
/// <param name="size">The size.</param>
|
|
/// <returns>SizeF.</returns>
|
|
public static SizeF ScaleSize(SizeF size)
|
|
{
|
|
return new SizeF(ScaleWidth(size.Width), ScaleHeight(size.Height));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Scales the width.
|
|
/// </summary>
|
|
/// <param name="w">The w.</param>
|
|
/// <returns>System.Int32.</returns>
|
|
public static int ScaleWidth(int w) => Convert.ToInt32(w * DpiScaleFactor);
|
|
|
|
/// <summary>
|
|
/// Scales the width.
|
|
/// </summary>
|
|
/// <param name="w">The w.</param>
|
|
/// <returns>System.Single.</returns>
|
|
public static float ScaleWidth(float w) => Convert.ToSingle(w * DpiScaleFactor);
|
|
|
|
/// <summary>
|
|
/// Uns the height of the scale.
|
|
/// </summary>
|
|
/// <param name="h">The h.</param>
|
|
/// <returns>System.Single.</returns>
|
|
public static float UnScaleHeight(float h) => Convert.ToSingle(h / DpiScaleFactor);
|
|
|
|
/// <summary>
|
|
/// Uns the width of the scale.
|
|
/// </summary>
|
|
/// <param name="w">The w.</param>
|
|
/// <returns>System.Single.</returns>
|
|
public static float UnScaleWidth(float w) => Convert.ToSingle(w / DpiScaleFactor);
|
|
}
|
|
} |