Closed vyuzhanin closed 1 year ago
This is one of the reasons that the documentation recommends against using SetHighDpiMode()
. You should, if possible, set this value in the application manifest. Or make sure it is the very first thing your application does—prior to initializing other libraries. In fact, since BarcodeLib does not initialize itself until you construct/reference it, you already have the power to fix this: you can make sure you initialize winforms prior to initializing Barcode
.
From the docs
We recommended that you specify the default process DPI awareness via a manifest setting. While specifying the default via API is supported, it is not recommended.
From the Application.SetHighDpiMode()
docs
If an application carries an application manifest file and the DPI mode was set in that file, this method will fail to set or change the mode that was already set by the application manifest. The high DPI mode is set once per process. For more information about setting the DPI mode via the application manifest file, see Setting the default DPI awareness for a process.
you can make sure you initialize winforms prior to initializing Barcode
I wish I could to fix it faster but I have a big dependency injection procedure before creating a main form. Sure I'll apply some patterns like lazy load to barcodelib and dependencies which is runnig the library but anyway it seems strange.
If you are using winforms, that is sort of something that must exist outside of dependency injection. A GUI application is already a special thing on Windows…. As the documentation I referenced states, you really should be specifying HiDPI in your application’s manifest instead. Then this wouldn’t even matter. Is that not an option for you?
Closing this as resolved per Binki's answer. I concur.
Barcodelib: 2.40 Platform: net5.0-windows
When I try to create the instance of Barcode class before I run wInforms application then it draws a huge font on main form. Here is code to rperoduce the issue:
Here is the example with normal font:
Here is the example with huge font because of Barcode class:
This issue is not happends when barcode initialized inside the aplication form. And maybe it happends on net5 only I didn't check it on another platforms.