DIP
Home
Classes
DIP
About
Windows Forms haven’t been build with HDPI support in mind. If you are using a monitor with a high-density display, the whole GUI seems to be very tiny. If you turn on DPI-aware, GUI gets scaled as an image which results in very blurry text and overall unpleasant viewing experience. That’s where Dip class comes handy. Instead of scaling GUI as an image, we simply define a new distance unit called DIP which stands for device independent pixel and our GUI gets scaled at runtime without any unpleasant visual artefacts. This unit will be transformed into actual pixels on every machine differently depending on the scale setting of Windows. This will cause that on every Windows device we will always get the same size of UI element independently of viewing device resolution or set scale percentage.
1080p
100x100 pixels square on 1920x1080 pixels monitor (125% scale).
4K
100x100 pixels square on 3840x2160 pixels monitor (125% scale).
As you can see on the images above, in real life, 100 pixels looks much bigger on 1080p monitor than on 4K one. The number of pixels that fit into an inch is referred to as pixel density. High-density screens have more pixels per inch than low-density ones. As a result, UI elements of the same pixel dimensions appear larger on low-density screens, and smaller on high-density screens. Things get even more confusing when Windows scaling comes in. In next sections you will learn how to overcome those scaling problems using DIP class.
Usage
Some of the Windows Forms GUI components scale itself properly. Those who don’t can be easily fixed using DIP class. Instead of hard-coding pixel dimension values to the components, we can set them using DIP.Set() method and let Minimal library to figure out a final result for us. DIP class is also heavily used inside custom MItem objects where it is very important to take into account the density of the display. See example below:
public class CustomItem : MItem
{
public CustomItem()
{
// Default item height
// Uses device independent pixels to provide
// best scaling experience
Height = DIP.Set(60);
}
}
Those 60 device independent pixels will be converted to actual pixels on every machine differently depending on the display of the device. On a machine with 4K monitor will be actual size in pixels bigger than on low density device like portable windows tablet with 720p display.
Windows scale |
DIP |
Pixels |
100% |
100dip |
80px |
125% |
100dip |
100px |
150% |
100dip |
120px |
Class content
Assembly |
Minimal.dll |
Namespace |
Minimal.Scaling |
Inheritance |
- |
Attributes |
- |
Implements |
- |
Constructors
Properties
Name |
Description |
Type |
- |
- |
- |
Fields
Name |
Description |
Type |
- |
- |
- |
Events
Name |
Description |
Type |
- |
- |
- |
Methods
Name |
Description |
Returns |
Set(int dip) |
Converts dip pixels to standard pixels. |
int |