I've created a simple Winforms application in C#. When I run the application on a machine with high DPI settings (e.g. 150%), the application gets scaled up. So far so good!
But instead of rendering the fonts with a higher font size, all texts are just scaled up, too. That of course leads to very blurry text (on all controls like buttons etc.).
Shouldn't windows take care of rendering the texts correctly? For example my application's title bar is rendered crisp & clear.
Once you go past 100% (or 125% with the "XP-style DPI scaling" checkbox ticked), Windows by default takes over the scaling of your UI. It does so by having your app render its output to a bitmap and drawing that bitmap to the screen. The rescaling of that bitmap makes the text inevitably look fuzzy. A feature called "DPI virtualization", it keeps old programs usable on high resolution monitors.
You have to explicitly let it know that you can handle higher DPI settings by adding the <dpiAware> element to your manifest. The MSDN page is here but it isn't complete since it is omitting the UAC settings. Project + Add New Item, pick "Application Manifest File". Edit the manifest text or copy/paste this:
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
You can also pinvoke SetProcessDPIAware() in your Main() method, necessary for example if you deploy with ClickOnce:
[STAThread]
static void Main() {
if (Environment.OSVersion.Version.Major >= 6) SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); // Edit as needed
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
UPDATE, this common need is finally a bit easier if you use VS2015 Update 1 or higher. The added manifest already has the relevant directive, just remove the comments.
Keyword for search so I can find this post back: dpiAware
Applications can be developed in two different mode.
The first one is to declare our application to be non-DPI-aware (not declaring anything will default to this). In this case the operating system will render our application under the expected 96 DPI and then will do to the bitmap scaling that we discussed before. The result will be a blurry looking application, but with a correct layout.
The second option is to declare the application as DPI-aware. In this case the OS will not do any scaling and will let your application render according to the original DPI of the screen. In case of a per-monitor-DPI environment, your application will be rendered with the highest DPI of all the screens, then this bitmap will be scaled down to the proper size for each monitor. Downscaling results in a better viewing experience than upscaling but you might still notice some fuzziness.
If you want to avoid that, you must declare your application as per-monitor-DPI-aware. Then you must detect when your application is dragged across different monitors and render according to the DPI of the current one.
Declaring the DPI awareness is done in a manifest file.
refer the following link stackoverflow
Using .NET Framework 4.7 and Windows 10 Creators Update (1703) or newer you must do the following things to configure high DPI support for your Windows Form application:
Declare compatibility with Windows 10.
To do this, add the following to your manifest file:
<compatibility xmlns="urn:schemas-microsoft.com:compatibility.v1">
<application>
<!-- Windows 10 compatibility -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
Enable per-monitor DPI awareness in the app.config file.
Windows Forms introduces a new System.Windows.Forms.ApplicationConfigurationSection element to support new features and customizations added starting with the .NET Framework 4.7. To take advantage of the new features that support high DPI, add the following to your application configuration file.
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>
Important
In previous versions of the .NET Framework, you used the manifest to add high DPI support. This approach is no longer recommended, since it overrides settings defined on the app.config file.
Call the static EnableVisualStyles method.
This should be the first method call in your application entry point. For example:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
The advantage of this is the support for dynamic DPI scenarios in which the user changes the DPI or scale factor after a Windows Forms application has been launched.
Source: High DPI support in Windows Forms
None of these suggestions worked for me but, something happened after I removed the Form.Font = new ... from the Form.Design.cs, the form started to re-scale properly, it works if the Font is defined in the constructor or not at all. Why? somebody else may be able to explained, I just can talk about the changed I made and took me a few minutes to figured out it was the root cause for the form I was working on. Hope it helps.
Since at least Visual Studio 2017 you just have to add a manifest file and uncomment this section:
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
This is not an answer. This is my work around. None of the above answers or comments worked for me. I also searched for and tried other methods.
I have been using Visual Studio.NET with C# and Windows.Forms since it was originally released. Until VS 2022 and Windows 11 this year, setting the scale mode seemed to work fine. For some reason, some of my Form.Height values get reduced at run time. No problems so far with Form.Width being changed. For me, this problem started April 1, 2022 - so I first thought it was an April Fool's prank!
Anyway, I have given up trying solutions for now and decided it is more practical for me to just set the Form.Size in the constructor code.
I observe the Designer UI uses Size which it converts to ClientSize in its generated code as follows:
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(744, 109);
this.ControlBox = false;
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
My workaround in my Form's constructor looks like:
/// <summary>
/// Constructor
/// </summary>
public MyForm()
{
// In the designer, MyForm.Size was entered and displayed as 760, 148
InitializeComponent();
// At runtime, MyForm.Size is changed to 760, 111
// I will Reset this form's Size here so I can get full height again.
this.Size = new Size(760, 148);
}
Platform:
Windows 11 Professional
Microsoft Visual Studio Professional 2022
Version 17.1.6
VisualStudio.17.Release/17.1.6+32421.90
Microsoft .NET Framework version 4.8.04161
C# Tools 4.1.0-5.22165.10+e555772db77ca828b02b4bd547c318387f11d01f
HDMI 1920x1080 video (100% or no scaling)
I'm creating a cast-enabled application using the CastVideos-android sample project as a reference.
Version 1.2 of the CastVideos-android sample uses this forked version of the ShowcaseView library to display a very nice looking overlay to highlight the cast button.
This is great and helps developers satisfy the Cast Sender-App UI requirements, but this forked version of the ShowcaseView library doesn't play well with apps that may use multiple icons in the ActionBar.
For example, when adding a SearchView-type item to the ActionBar the ShowcaseView bugs-out.
The result is below and the steps to replicate this behavior are below the screenshot :
Steps to replicate:
Include the v7-appcompat as a library project in the CastVideo-android project.
Change the res/menu/main.xml in the CastVideo-android project to look like the following (adding an ActionView of type SearchView to the ActionBar) :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:compat="http://schemas.android.com/apk/lib/res/android.support.v7.appcompat" >
<item
android:id="#+id/media_route_menu_item"
android:title="#string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never"/>
<item
android:id="#+id/search"
android:icon="#drawable/abc_ic_search"
app:title="#string/menu_Search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="collapseActionView|ifRoom"/>
</menu>
I'm using the latest version of the v7-appcompat library.
I suspect the culprit to be how the ActionBarViewWrapper.getMediaRouterButtonView() method (found in com.github.amlcurran.showcaseview.targets) is finding the MediaRouterButton via reflection, but can't seem to understand how to find the MediaRouterButton if there are multiple icons items in the ActionBar.
Any help would be greatly appreciated!
The forked project has been updated to handle this case. Thanks for reporting the issue. Once I hear from you (or anyone else) that it works as expected, I will submit a pull request to Alex.
As you all know, once you have installed an extension in the Joomla backend, the description shows. You can either have a plain description from the XML or have a language based one. I have never had problems in the past with language based descriptions however this time I do. The extension is a admin component and has no frontend folder and is for Joomla 2.5.
When I install the component, the description appears as COM_PROJECTS_DESC
The language folder and files are in the correct location and the XML shows as
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="2.5.0" method="upgrade">
<name>Projects</name>
<author>JoomJunk</author>
<creationDate>15th Jul 2012</creationDate>
<copyright>Copyright (C) 2012 JoomJunk</copyright>
<license>http://www.gnu.org/licenses/gpl-3.0.html</license>
<authorEmail>admin#joomjunk.co.uk</authorEmail>
<authorUrl>http://www.joomjunk.co.uk</authorUrl>
<version>1.0.0</version>
<description>COM_PROJECTS_DESC</description>
<administration>
<menu img="components/com_projects/assets/images/cpanel_16.png">COM_PROJECT_TO_DO</menu>
<files folder="admin">
<filename>index.html</filename>
<filename>controller.php</filename>
<filename>helper.php</filename>
<filename>projects.php</filename>
<folder>views</folder>
<folder>tables</folder>
<folder>models</folder>
<folder>controllers</folder>
<folder>assets</folder>
</files>
<languages folder="admin">
<language tag="en-GB">languages/en-GB/en-GB.com_projects.ini</language>
<language tag="en-GB">languages/en-GB/en-GB.com_projects.sys.ini</language>
</languages>
</administration>
</extension>
The odd thing is, the description doesnt work when installing for the first time, but if I install the coomponent over it (upgrade) then it does work.
I have used the language debug tool the the language file seems to be loading so Im not sure what the problem is. I has only ever happend to me with extensions specifically for the admin backend and that have no frontend referrence.
Any help would be much apreciated.
Regards
You can display the installable description text and if you need to install any sample values through install.joomjunk.php.
I think this link will be helpful for you.
http://docs.joomla.org/Using_the_installer_API_to_support_package_installation
I am developing a Windows Phone 7 application. I noticed the Genre tag in WMAppManifest.xml, but was unable to do anything useful with it. How can I categorize my application to be a game? And if it's possible add it to a certain category in the games section.
<?xml version="1.0" encoding="utf-8" ?>
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment"
AppPlatformVersion="7.1">
<App xmlns=""
ProductID=""
Title=""
RuntimeType=""
Version=""
Genre="How can I use this?"
Author=""
Description=""
Publisher="">
Have a look at this:
http://msdn.microsoft.com/en-us/library/ff769509(v=vs.92).aspx#BKMK_Application
What I'm trying to do is take an XML document, let's say http://example.org/data.xml and show it with an XSL stylesheet applied.
(I cannot modify the document itself and add a directive)
So there are a couple of utility XML files like this:
wrapper.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wrapper [
<!ENTITY content SYSTEM "http://example.org/data.xml">
]>
<?xml-stylesheet type="text/xsl" href="unwrap.xsl" ?>
<wrapper>
&content;
</wrapper>
unwrap.xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="stylesheet.xsl"/>
<xsl:template match="/wrapper/node()[1]">
<xsl:apply-imports/>
</xsl:template>
</xsl:stylesheet>
So to summarize: stylesheet.xsl is written for http://example.org/data.xml, the browser is pointed to wrapper.xml and the user should see the transformed http://example.org/data.xml.
This is one of those rare cases where things work as expected in IE (and Chrome) but not Firefox.
AFAIK Firefox supports external XML entities, but it seems like they are invisible in XSL code. I found this article from 2006, it describes this problem in Firefox 1.5 (I'm using 3.5.3)
Is there any workaround for this?
That XML looks familiar ;)
Currently, FireFox will not load external DTD's and entity references, because of security and Denial of Service concerns. For example: http://en.wikipedia.org/wiki/Billion_laughs
There is an open Mozilla bug describing the reasons why and lengthy debate about whether or not to make it something that is configurable: https://bugzilla.mozilla.org/show_bug.cgi?id=22942
There does appear to be one workaround to loading DTDs, but I'm guessing that probably isn't a viable solution for you.
Firefox will load local DTD files
if you put them in this directory for Windows:
C:\Program Files\Mozilla Firefox\res\dtd\...
The directory for Linux:
/**mileage may vary**/MozillaFirefox/lib/res/dtd/
One idea to get around using the entity reference:
If you can control the content of the wrapper.xml, then you could fetch the contents of http://example.org/data.xml (server side) and echo it out as the full contents of the wrapper file, with the addition of the Stylesheet Processing Instruction(assuming you have some dynamic server-side capabilities).