-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from pstranak-sw/feature/hiDpiSupport
Support for HiDPI
- Loading branch information
Showing
16 changed files
with
95 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...lStudio/3rdParty/ScintillaNET-FindReplaceDialog/FindReplace/FindReplaceDialog.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace SwqlStudio.Utils | ||
{ | ||
/// <summary> | ||
/// A helper class for supporting font and DPI scaling | ||
/// </summary> | ||
/// <remarks> | ||
/// <para>This dimensions of the default font are used to calculate a proper DPI scaling ratio of elements. .Net Framework tries to use "MS Sans Serif" | ||
/// from Windows 3.1, which isn't available anymore. So the system automatically replaces it with "Microsoft Sans Serif", or sometimes with "Tahoma". | ||
/// But those are too old and don't match with Windows UI fonts. And if there are elements using also other fonts, like "Segoe UI", it messes up the calculation. | ||
/// That can happen especially when a different font is used for rendering than for the DPI scaling calculation.</para> | ||
/// <para>This should not be needed anymore in .Net Core 3.1 and .Net 5: https://github.com/dotnet/winforms/pull/656 </para> | ||
/// </remarks> | ||
internal static class DpiHelper | ||
{ | ||
/// <summary> | ||
/// The default font used in SWQL Studio dialogs | ||
/// </summary> | ||
/// <remarks>Returns the default .Net font.</remarks> | ||
/// <value>Microsoft Sans Serif, 8.25F</value> | ||
public static readonly Font DefaultFont = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 0); | ||
|
||
/// <summary> | ||
/// Sets the <see cref="DefaultFont"/> as the default font for the <paramref name="control"/> | ||
/// </summary> | ||
/// <param name="control">Usually a <see cref="Form"/></param> | ||
/// <remarks>This is needed to correctly calculate a proper DPI scaling ratio of the <paramref name="control"/> and its child elements. | ||
/// It forces the <paramref name="control"/> to sync the fonts used for its rendering and DPI scaling calculation. | ||
/// <para>This should be called in the <paramref name="control"/>'s constructor.</para></remarks> | ||
public static void FixFont(Control control) | ||
{ | ||
control.Font = DefaultFont; | ||
} | ||
|
||
/// <summary> | ||
/// Adjusts the default row height in a <see cref="DataGridView"/> | ||
/// </summary> | ||
/// <remarks>The default row height is defined as the height of the default font + 9 pixels. | ||
/// This method, when called after <see cref="FixFont"/>, forces the recalculation of the height.</remarks> | ||
public static void FixRowHeight(DataGridView dataGridView) | ||
{ | ||
// Instead of "dataGridView.DefaultCellStyle.Font.Height" we could just hard-code "DefaultFont". That way, this method would not depend | ||
// on a previous call to "FixFont". But this is a bit more universal solution. | ||
dataGridView.RowTemplate.Height = dataGridView.DefaultCellStyle.Font.Height + 9; | ||
} | ||
} | ||
} |