-
Notifications
You must be signed in to change notification settings - Fork 984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow set font application-wide #3001
Comments
We should totally do this for .NET 5, I think this is a great idea. |
Are you going to throw an exception when the |
I propose we follow the same pattern set by winforms/src/System.Windows.Forms/src/System/Windows/Forms/Application.cs Lines 1208 to 1215 in 18f1c81
The rationale behind it, if a form has been created, it may have been laid out and rendered using one font, the font may have been cached etc., and setting a new font could be detrimental from both performance and UX. |
Is there already a way to get the default font? (Get/set symmetry) |
probably |
Might be worthwhile to add a corresponding [STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Set default to 10pt
var font = Application.GetDefaultFont();
font = new Font(font.FontFamily, 10f);
Application.SetDefaultFont(font);
Application.Run(new Form1());
} It would be odd if users had to call |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The rationale behind this FR is to allow users to set the original font, that may have been used to design the app (i.e. Font-scaling pixel-perfect design scenario), to help with a migration from .NET Framework to .NET Core/.NET. I don't feel that leveraging the default font to change its properties fits the above scenario. And, to be honest, I'm struggling to think of a use-case that would require this. |
This comment has been minimized.
This comment has been minimized.
No objections, you're the domain expert. We just generally strive to avoid asymmetries like set-only APIs. |
So do we, but in this case we want to have set-once kind of API, akin to |
Reviewed and approved offline: namespace System.Windows.Forms
{
public partial class Application
{
public void SetDefaultFont(Font font);
}
} |
We can now implement this proposal. #4909 will facilitate a communication of the the font information to the designer process. |
@RussKie #4009 is grate! But, I want to point out some one thing that related to this issue and #4009 too. It's system font scaling: P.s. I want to remind some old annoying DataGridView Designer issue, that become more annoying due to working font scaling in .net. And I think it definitely needs to be addressed 😋 |
This comment has been minimized.
This comment has been minimized.
With Windows 10 21H2 changing the System font to Segoe UI Variable with its Small, Text, and Display OpticalSize variants - will WinForms be ready to handle that, and will there be suitable fallbacks for Windows 8, and older Windows 10 versions? |
Yes, becouse .net framework doesn't respect system font, and .net core does (#656). But font scaling in .net will work only if you not set font explicitly (then it will be taken from |
They are in fact different in net6.0 scenarios :) |
Thanks for the link. We get the default font from .NET runtime, and take it for granted: winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs Lines 1807 to 1819 in c93d8c8
If you're running that build already you could probably run a test yourself and see: I think it may just work out of the box... @safern any thoughts? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The default font has been updated in .NET Core 3.0 (dotnet#656) and documented. However for some users who built their apps in pixel-perfect manner this change has proved to be a significant hurdle in migrating their apps to .NET. Allow setting application-wide default font in a similar manner we set high dpi or visual styles: Application.SetDefaultFont(new Font(new FontFamily("Calibri"), 11f)); * The application-wide default font can only be set before the first window is created by an application. * The font will be scaled by the system text scale factor, whenever it is getting changed. Resolves dotnet#3001
The default font has been updated in .NET Core 3.0 (#656) and documented. However for some users who built their apps in pixel-perfect manner this change has proved to be a significant hurdle in migrating their apps to .NET. Allow setting application-wide default font in a similar manner we set high dpi or visual styles: Application.SetDefaultFont(new Font(new FontFamily("Calibri"), 11f)); * The application-wide default font can only be set before the first window is created by an application. * The font will be scaled by the system text scale factor, whenever it is getting changed. Resolves #3001
The default font has been updated in .NET Core 3.0 (#656) and documented. However for some users who built their apps in pixel-perfect manner this change has proved to be a significant hurdle in migrating their apps to .NET. Allow setting application-wide default font in a similar manner we set high dpi or visual styles: Application.SetDefaultFont(new Font(new FontFamily("Calibri"), 11f)); * The application-wide default font can only be set before the first window is created by an application. * The font will be scaled by the system text scale factor, whenever it is getting changed. Resolves #3001
Verified the issue with latest 6.0.0-preview.5.21275.7, the main functions have been fully merged/implemented, found a new issue too and filed it as #4978 |
Question: Can WPF set default font? rather than set FontFamily in every xaml. I had googled it but got no answer. Edit: I managed to set it by It's the first time I monkey patch in C#, interesting. Previously I only did this kind of things in Python. |
@imba-tjd you can try setting the default value of the FontFamily and related properties in the metadata before creating any window or control. In general this is the wrong repo to ask in though, you'll find more people knowing about WPF in the WPF repo. |
Is your feature request related to a problem? Please describe.
The default font has been updated in .NET Core 3.0 (#656) and documented. However for some users there is still an element of surprise when they migrate their apps to .NET Core.
We've received several questions regarding different sizes of forms (e.g. #1122, #1827, etc.).
Whilst the new default font is here to stay, some users may wish to retain the original font (e.g. due to a design of their app). However for an application with more than a handful of forms, setting the original font may be tedious and cumbersome exercise.
Describe the solution you'd like
Add the ability to set an application-wide font, similar to
SetHighDpiMode()
orSetCompatibleTextRenderingDefault()
methods.API Proposal
API Usage
Will this feature affect UI controls?
No
The text was updated successfully, but these errors were encountered: