Spread Windows Forms 13.0 Product Documentation
Spread Windows Forms 13.0 Product Documentation / Developer's Guide / Getting Started / Working with the Component / Adding Support for High DPI Settings
In This Topic
    Adding Support for High DPI Settings
    In This Topic

    Spread supports high DPI settings provided that the application has high DPI support enabled.

    Refer to Microsoft's web site for more information about enabling DPI support for your application.

    Enabling DPI support in .NET 4.5.2

    You can refer to the following steps for a general example of how to enable DPI support in .NET 4.5.2.

    1. Use the Windows API with the following code.
      Code
      Copy Code
      static class Program
      {
          /// <summary>
          /// The main entry point for the application.
          /// </summary>
          [STAThread]
          static void Main()
          {
              SetProcessDPIAware();
              Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new MainForm());
          }
       
          [System.Runtime.InteropServices.DllImport("user32.dll")]
          public extern static IntPtr SetProcessDPIAware();
      }
      

      Note: The SetProcessDPIAware API must be called before any window is created; otherwise, a window created before using this API will have the wrong size and font.

    2. Add Spread code:
      Code
      Copy Code
      //add code in InitializeComponent() of cs file
      this.fpSpread1.SpreadScaleMode = FarPoint.Win.Spread.ScaleMode.ZoomDpiSupport;
      this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
      
    3. Enable Windows Forms High DPI support by adding code to the App.config.
      Code
      Copy Code
      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
        <appSettings>
          <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
        </appSettings>
      </configuration>
      

    Enabling HDPI for .NET Framework 4.7

    Use the following steps to enable DPI support.

    1. Install the .NET 4.7 Framework.
    2. Create a new windows forms application.
    3. Add an App.config with the following information to the root directory of the form (same directory as Program.cs).
      Code
      Copy Code
      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <startup>
          <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
        </startup>
        <System.Windows.Forms.ApplicationConfigurationSection>
          <add key="DpiAwareness" value="PerMonitorV2"/>
          <!-- Uncomment each value to disable the fixes one by one. -->
          <!--
          <add key="Form.DisableSinglePassScalingOfDpiForms" value="true"/>
          <add key="ToolStrip.DisableHighDpiImprovements" value="true"/>
          <add key="CheckedListBox.DisableHighDpiImprovements" value="true"/>
          <add key="MonthCalendar.DisableHighDpiImprovements" value="true"/>
          <add key="AnchorLayout.DisableHighDpiImprovements" value="true"/>
          <add key="DataGridView.DisableHighDpiImprovements" value="true"/>
          -->
        </System.Windows.Forms.ApplicationConfigurationSection>
      </configuration>
      
    4. Add an App.manifest with the following information to the root directory of the form (same directory as Program.cs).
      Code
      Copy Code
      <?xml version="1.0" encoding="utf-8"?>
      <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
        <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">
              <!-- UAC Manifest Options
                   If you want to change the Windows User Account Control level replace the
                   requestedExecutionLevel node with one of the following.
              <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
              <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
              <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
                  Specifying requestedExecutionLevel element will disable file and registry virtualization.
                  Remove this element if your application requires this virtualization for backwards
                  compatibility.
              -->
              <requestedExecutionLevel level="asInvoker" uiAccess="false" />
            </requestedPrivileges>
          </security>
        </trustInfo>
        <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
          <application>
            <!-- A list of the Windows versions that this application has been tested on and is
                 is designed to work with. Uncomment the appropriate elements and Windows will
                 automatically selected the most compatible environment. -->
           
            <!-- Windows 10 -->
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
          </application>
        </compatibility>
        <!--<application xmlns="urn:schemas-microsoft-com:asm.v3">
          <windowsSettings>
            <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
          </windowsSettings>
        </application>-->
       
      </assembly>
      
    5. Verify that Program.cs has the following settings.
      Code
      Copy Code
      static class Program
          {
              /// <summary>
              /// The main entry point for the application.
              /// </summary>
              [STAThread]
              static void Main()
              {
                  Application.EnableVisualStyles();
                  Application.SetCompatibleTextRenderingDefault(false);
                  Application.Run(new Form1());
              }
          }
      
    6. Check that Form1.designer.cs has the following settings.
      Code
      Copy Code
      this.fpSpread1.SpreadScaleMode = FarPoint.Win.Spread.ScaleMode.ZoomDpiSupport;
      this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;