How to distribute VisualStyles for dialogs Vista style - FIXED!
I created a self-contained package and it works. Problem is that in my project C# WinForms, I use System.Windows.Forms.VisualStyles to have dialogs in Vista style, but the sytle is not applied as if I used normal dialogs.
What should I distribute to make it work?
Note that the software works as expected if executed from Debug folder or from the IDE itself, but not from the Release folder after the self-contained packags is created.
12 Replies
how do you use System.Windows.Forms.VisualStyles exactly
@reflectronic
you're using .NET Framework, right? like .NET 4.x
$code is how you do that
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/I see WindowsApiCodePack, which is fx only https://www.nuget.org/packages/WindowsAPICodePack-Core/#supportedframeworks-body-tab
WindowsAPICodePack-Core 1.1.2
Core library for Windows API Code Pack
GitHub
GitHub - aybe/Windows-API-Code-Pack-1.1: Windows API Code Pack 1.1
Windows API Code Pack 1.1. Contribute to aybe/Windows-API-Code-Pack-1.1 development by creating an account on GitHub.
My target framework is ".NET 8.0". The weird thing is that if I run the executable from the "bin\Release\net8.0-windows\publish\self-contained" folder I have the glitch, while from the "bin\Debug\net8.0-windows" it runs ok, so also on the same development machine!
if you are using .NET 8 i would suggest not using Microsoft.WindowsAPICodePack
there is a task dialog built into windows forms https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.taskdialog?view=windowsdesktop-8.0
TaskDialog Class (System.Windows.Forms)
A task dialog allows to display information and get simple input from the user. It is similar to a MessageBox (in that it is formatted by the operating system) but provides a lot more features.
i don't know exactly why you are seeing different behavior but you need to enable visual styles to use the task dialog, and you can do it either through calling
Application.EnableVisualStyles()
, or adding an app manifest with the reference to the right common controls library. if it's not working in your release build, then those things aren't happening for whatever reason and that needs to be debugged@reflectronic Main main method is:
I also have a manifest file called <executable-file-name>.exe.manifest in the same folder of the executable itself: ...\bin\Release\net8.0-windows\publish\self-contained.
The error message I receive in the exception is: Value cannot be null. (Parameter 'path1')
There is no parmeter "path1" in my code:
What can I also check? As I said, the executable in bin\Debug\net8.0-windows runs without this issue.
Ok, I fixed it. In Publish, I went to "Show all settings" and in the "Profile settings" window I clicked the "File publish option" at the bottom and unticked the "Produce single file" setting. And this did the trick!!!
I got a folder with many files, but same overall size, and much smaller executable size, that can be useful in case I should deliver an update of the executable only in future.