wpf / Visual Studio default styles - wpf

If I open a new project, and put a label or button on the main window, I get the Segoe UI font at size 12px.
Where is this coming from? Can I choose what I would like the default font / size to be? I had a good look around but can't find anything.
Thanks

The available fonts are set according to System.Windows.Media.Fonts.SystemFontFamilies.
If multiple versions of the same font family reside in the same directory, the Windows Presentation Foundation (WPF) font enumeration returns the most recent version of the font. If the version information does not provide resolution, the font with latest timestamp is returned. If the timestamp information is equivalent, the font file that is first in alphabetical order is returned.
There is also Fonts.SystemTypefaces.
Presumably it is possible to change the selected family or create your own. In fact it is, this post (WPF - Add Custom Font) gives more information on this.
I hope this helps.

Related

WPF In-Code Preview Colour Feature VS2019

I would like to know if there is a setting for WPF in VS2019 to enable "colour preview" in code, such that when I type the hex colour code it displays the colour (without having to apply the colour to any UI element – just a pure visual preview)?
I have a project, where I use a multitude of colours, and it is getting difficult to keep track of which colour is which, so it would be nice to have a visual guide.
My general code for colours in the Resource Dictionary is:
<Color x:Key="BackgroundLight">#efefef</Color>
<SolidColorBrush x:Key="BackgroundLightBrush" Color="{StaticResource BackgroundLight}" />
Is there such setting in VS2019? I believe I saw something like this in one youtube video, where the hex code was underlined by the corresponding colour, but I can neither figure out how to achieve that, nor can I find the video now.
The newest version of VisualStudio implements this by default now. There is a coloured square next to the colour’s name. Nice.
You can sometimes persuade the colour picker to appear in the properties window.
It is fiddly though and I must admit I can't recall trying with vs2019.
EDIT:
Having just tried this, I couldn't get it to work with just a color. A control like say the background on a grid with the hex in it works ok but the colorpicker doesn't respond at all when I select a color resource.
There's a vsix
https://marketplace.visualstudio.com/items?itemName=NikolaMSFT.InlineColorPicker
Like you're doing, I usually define colours in a resource dictionary so they have meaningful names.
Once I've done that, the actual colour matters a lot less.
There's a vsix
https://marketplace.visualstudio.com/items?itemName=NikolaMSFT.InlineColorPicker
This extension can't be installed in VisualStudio 2019 Pro, but you can use this method mentioned in another answer as workaround to install it in VisualStudio 2019 Pro.
https://stackoverflow.com/a/62040646/7387963

What's the Microsoft font that looks same/closer to 'Estrangelo Edessa'?

I am facing display issues with winforms in window 10 OS. The fonts used for forms is 'Estrangelo Edessa’. In windows 10, this font doesn't come installed by default and hence text/content looks ugly (cutoff/improperly sized). So i am thinking to change the font that looks closer to 'Estrangelo Edessa' and will be native to windows 7, 8 and 10. Please suggest one such font.
I suggest trying Verdana or Lucida Sans Unicode as they have similar proportions to Estrangelo Edessa. Alternatively, Calibri is narrower but otherwise similar and nicer to read.
You may also want to look into having your forms size the controls so text is never cut off, just in case. For example, all WinForms controls have a PreferredSize property.

Query Windows' Color and Appearance

I am writing a small GUI library in OpenGL for fun and profit. When it comes to font handling, so far I require the client application to explicitly load all fonts and set them on the widgets. So far this is ok, I also have a means to set them once as a default for all widgets of a certain type.
Although this is feasible, I though, would it not be dandy to use the system's default font as a default instead. In the case of Windows this would be the fonts that are configured though the Color and Appearance dialog.
After warming up my rusted Win32 programming knowledge and souring the MSDN I can't find an awnser to this question. I can load a font by name and set it on any widget, but figuring out what font Win32 would use as a default eludes me.
So far the best I have found is the SystemParametersInfo function with SPI_GETNONCLIENTMETRICS. But these are just the settings for the "non client" area, such as window title bar and such.
DEFAULT_GUI_FONT is not your solution. The name certainly sounds good, and indeed it was the default GUI font at some point in history, but that font hasn't been used in years.
You already stumbled upon the correct solution: calling SystemParametersInfo with the SPI_GETNONCLIENTMETRICS option. This will fill in a NONCLIENTMETRICS structure with information about the standard system fonts.
The "standard UI font" in that structure is called lfMessageFont. It is the one used for text in message boxes, dialog boxes, and elsewhere in the client area of windows. It is the same one configurable in the "Appearance" properties.
I wrote out a very detailed answer about fonts in Windows applications a few years ago. That one kind of focuses on MFC, so I've chosen not to mark this question as a duplicate of that other one and compose a separate answer, but really all of the information you need is there.
For fun, I'll throw in that you can get the system colors by calling the GetSysColor function. Pass one of the COLOR_* values to indicate which color you want; you'll get back a COLORREF value (typedefed as a 32-bit unsigned integer into which are packed the red, green, and blue component values of the color). Use the GetRValue, GetGValue, and GetBValue macros to extract the individual components; I doubt OpenGL wants COLORREF values.

How to verify font created by Windows?

I'm using the ChooseFont system dialog to populate a LOGFONT structure that is passed to CreateFontIndirect and the resulting font handle is selected into the device context and used. But it doesn't resemble the requested font in any way (well, OK, similar character sets, but otherwise not the same). Here's an image of the screen showing the ChooseFont dialog selecting an old DOS-style VGA font and in the background (behind the ChooseFont dialog) shows the font that I got when I selected the values shown in the dialog:
Notice that the Sample in the dialog and what Windows puts on the screen when the created font is selected into the DC are quite different. This doesn't happen for ALL fonts, only some of them, which is why I'm trying to correct and/or detect this.
I've tried getting the LOGFONT for the new font from the DC using (GetCurrentObject and GetObject) and it is identical to my request, except that the lfQuality has changed to NONANTIALIASED_QUALITY from anything else I've tried setting it to.
I have a kinda two part question:
How can I force Windows to use the font I've selected. Obviously there is a way, or it wouldn't look right in the ChooseFont dialog, either.
If no one can answer #1, how can I reliably find out that Windows has selected a totally wrong font, when asking Windows for the font info about the created font when selected into the device context doesn't work?
EDIT: July 8
If this helps at all, my basic calling sequence is:
LOGFONT lf;
CHOOSEFONT cf;
HFONT hf;
cf.lpLogFont = &lf; // plus other necessary stuff
ChooseFont( &cf );
hf = CreateFontIndirect( &lf );
SelectObject( hdc, hf );
ExtTextOut( hdc, ... );
Then, when I use the font, it doesn't always match what I requested. At all. (I just tried using Arial Monospaced MT and was rewarded with Courier -- Lucida Console would be a better substitute, at least it doesn't have serifs!) I don't do ANYTHING to the DC other than call GetDC(). I don't call any GDI setup/configuration functions, either, so I'm in whatever default mode one gets with a standard Windows program written in C to the WIN32API.
I've discovered that the Windows version of PuTTY shows the correct fonts while my program doesn't, but I have not yet been able to find anything different between the functions/parameters it uses to handle font creation and the way I do it. I'll keep looking though. Thanks to anyone who's given my question any thought, with or without suggestions. :-)

Searching for a default "check mark" icon

I am currently searching for an icon that shows a green check mark, such as this:
Basically what I want to do is the following: My C# WPF application contains a ListView with some entries and each of the entry gets validated. Depending on the outcome of the validation, such a green check mark or a red cross should be displayed.
I found a very nice red cross in the class SystemIcons. It is called SystemIcons.Error. The SystemIcons class also provides other icons like "Exclamation", "hand", "Shield", "Question" and various other icons, however there is no such a check mark thing.
Does anyone know whether such a check mark icon exists in some default library? I googled but I could not find anything alike. In case there is no such Icon, I would have to take some image from the web (like I posted here), but that would be the last option since my application should look consistent and I'm pretty sure Microsoft uses lots of those green things in many places of Windows. So there must be some icon I could use, right?
Best wishes,
Christian
If you're using one of the full versions of Visual Studio, you could always check out the Visual Studio Image Library that comes with Visual Studio.
I'm double checking now to make sure it contains something like what you're looking for.
What size icon images do you need?
If 16x16 will do then I'd recommend the silk icon set at famfamfam.com. This set is nice and consistent, and contains a green check mark.

Resources