I cann't make my application to apply Windows visual styles.
Application.EnableVisualStyles() in program.cs not changing RenderWithVisualStyle property to true.
[STAThread]
public static void Main(string[] startArgument)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
.....
}
Interestingly if I'm debugging with "Enable visual studio hosting process", Application.EnableVisualStyles() works as expected, RenderWithVisualStyle goes to true and styles are applied. But no styles without hosting process either Debug or Release mode.
Changing target framework v.2 to v.3.5 makes nothing.
Any ideas please, I'm stuck with this issue and googling for 3 days with no success.
Many thanks
You need to embed a manifest XML file that specifies that the new version of the common controls DLL should be used. See the MSDN article on visual styles for more information on how to do this.
Related
In Ubuntu, installing themes are as easy as copy-pasting GTK theme into the themes folder, then with the tweaks tool we can select the theme.
I couldn't find a working solution or workaround to apply themes.
Steps I have tried:
Installing the runtime
The GTK runtime I am using is
https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases.
Get a theme from https://www.pling.com/p/1246387/
Extract the content to C:\Users\username\AppData\Local\Gtk\3.24.24\share\themes
Edit settings.ini on C:\Users\Seiko Santana\AppData\Local\Gtk\3.24.24\etc\gtk-3.0\settings.ini putting gtk-theme-name=Ultimate-Dark-(Cpt)-Violet
Run any GtkSharp application.
It is still loading Adwaita theme. Did I miss something? I'm developing on .NET 6 and GtkSharp if that matters.
Thanks in advance.
I put the theme file under the themes directory like so:
, and added the following code right after Init (if I put it before that, it causes a null exception).
public static void Main(string[] args)
{
Application.Init();
Gtk.Settings.Default.ThemeName = "Ultimate-Dark-(Flat)-Violet";
and it worked:
Without that line, the default theme is like this, so it definitely worked.
I'm having an odd issue with Visual Studio Community 2015. My program runs correctly inside the Visual Studio Editor, and it also runs correctly when the Application .exe is double clicked in the bin/debug/ directory. However, when the Application is run anywhere else on the computer (including the Release directory) the program does not run correctly. I am definitely copying all of the Debug folder to the location of attempted execution so it's not because of that.
When I run the executable, a loading icon appears on the mouse, in Task Manager it appears as a process using about < 500K RAM and stays there until reboot. No window appears at all, and it is impossible to end the process once it has started, meaning it cannot be deleted.
I'm using .NET 4.5.2 primarily however I've tried 4.5 and 4.6 and neither fixed the issue (I've checked and I have all 3 of them installed). I also tried copying the System DLLs locally and that didn't fix the issue either. I also tried creating a minimalist solution (below) containing a project that only printed "Hello World" and quit.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
Console.ReadLine();
}
}
}
This program experienced the same issues except it couldn't even be run within the Debug folder, only within Visual Studio. I then changed the project so it opened, then closed again straight away without printing anything so that it didn't use the System libraries at all, and it did the same thing. I then tried running the program in both 64 and 32 bit forced, (on a 64 bit laptop) and that didn't make a difference either.
I'm using Windows 7 Home Premium - Visual Studio Community 2015
Thanks for any help :)
Another possibility for such a rare issue could be your Anti-Virus program. Some of them like to inject an DLL into each created process to better protect you. But this can also lead to such awkward problems.
The only other way that comes to my mind would be to check the Event Viewer or run Process Monitor to get an idea where the error comes from.
Try using the release configuration and enable Break on all exceptions (Check Managing Exceptions with the Debugger for help on enabling the VS exception handling).
Hopefully this will break visual studio and show you enough information on the exception.
You can also try using Process Monitor to find the issue.
I would highly recommend using a simple hello world program to find out the root cause. My suspicion is on some corrupt .NET framework installation
That's because it's not the proper exe...
In order to get a proper working .exe for you App Right Click on your project in Solution Explorer > Go to "publish" tab > select Publish Now
(Now go to debug folder and find exe)
It will automatically open the "publish" folder which has files for install, but NOW go to your "debug" folder and you will find the working exe there and some other Visual Studio generated files releated to publish that you don't really need
~ ChenChi
I have created an application in visual studio 2010 using C#.net.
In that application I am generating MS-Word report...
For that I have used SaveFileDialog for saving that documnet to a particular location..
Initally it was woking fine...But from some days my SaveFileDialog window is not getting opened on my system.
Same code is working on other machines without any problem.
Things I have done to fix this problem :
Uninstall VS 2010 and reinstall it.
Installed VS 2012
But that problem is still there.
P.S. I have Windows 7 O.S. 64-bit
Any help would be appreciated.
SaveFileDialog will only operate if it is used from a thread set to single-threaded-apartment.
Ensure that the thread you are using to display it is set to that mode.
If you are calling it from the Main() thread, ensure that Main() is marked with the [STAThread] attribute like this:
[STAThread]
private static void Main()
{
If I copy all the files from the debug (or release) folder and paste it somewhere it stops working before open and process disappears without any message. Anyway everything seems to be fine in debug or release folder. Any Ideas?
As I'm trying to execute assembled files, I'm not able to debug it.
There could be any number of issues from missing assemblies, permissions etc, you can debug an executable from within Visual Studio if its running or not, the following links show you how to attach a process, or EXE, to the Visual Studio debugger.
How to: Debug an Executable Not Part of a Visual Studio Solution
Attaching to Running Processes
You'll need to catch the exception to solve it. It can be due to almost anything ranging from references not found to IO-permissions etc.
For an easy way of just knowing fast, wrap your Main() in a try-catch and show a messagebox with the error.
[STAThread]
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
A recommended solution would be to implement some kind of robust logging as log4net or such before going into production.
All,
I have a WPF application built upon SQLite database and user/application Configuration settings. The application builds and runs fine in development environment. I created a Setup and Deployment project, added the "Project output" of above said application and then proceeded to create a setup. The pre-requisites and the .NET Framework versions are same in the Application and in the setup project:
.NET Framework 3.5 Client Profile
MS Visual Basic Powerpacks 10.0.0
Windows Installer 3.1
But when I move it onto another PC with identical .NET Framework installed (but without the development environment), the application does not start. It gives a "has encountered a problem and needs to close" Error. I found that this would mean a uncaught exception in the application. So, I tried to comment out parts of the application that did not have them handled and left all but a single window to display (the Main window that does nothing) but yet the application fails. I begin to suspect that the problem could be that the dependancies are not handled for the app start. Here is what I did with them:
SQLite needed a DLL that is automatically added to the "Detected Dependencies" It gets copied to the Application Directory
SQLite databases are added manually to the project and they are copied to the Application Directory
The Application.exe.config files are NOT copied. I am not sure where to put them
At this point, I would like to know how I can find out the root-cause for the problem. I tried running another simple app with a single window (and no functionality) and it works on the target machine. TIA
If you think the problem lies in the dependencies then it might be worth having a look at the "Assembly Binding Log Viewer" (i.e. fuslogvw.exe). This tool should be able to tell you exactly which assemblies were requested and how the requests were satisfied, or not satisfied. The catch is that this only works for managed assemblies.
If however you want to find out what the unhandled exception is then you could wrap a try .. catch around the application entry point. The catch in WPF is that this is generated by the compiler / Visual Studio so you can't normally change it. If you do want to change it, say to put a try .. catch around it then you need to (example taken from http://www.infosysblogs.com/microsoft/2008/09/how_to_write_custom_main_metho.html):
Find the App.xaml and App.xaml.cs files
Open the property page for App.xaml and change the build action to 'Page'
In App.xaml.cs add a Main() method which should look like:
[STAThread]
public static void Main()
{
var app = new App();
app.InitializeComponent();
app.Run();
}
If you wrap a try .. catch around the entire method body then you could write what ever the error information is to a text file. Hopefully that will help you find out what is wrong.
===== EDIT =====
If the unhandled exception is not being caught by the try .. catch construct then it can be a binder problem. Because the JIT compiler compiles methods on a as-needed basis it may help to move nearly all code out of the entry method. For example:
<!-- language: lang-cs -->
[STAThread]
public static void Main()
{
try
{
MyMethod();
}
catch(Exception e)
{
// ... Write to file here
}
}
private static void MyMethod()
{
// .. Do actual work here
}
By doing this you make sure that you are inside the try .. catch construct before the run-time tries to locate the right assemblies etc. However note that there are some exceptions that can't be caught (OutOfMemoryException, StackOverflowException and some others).
Have you considered using the ClickOnce deployment option for your application?
As you can see from this SO question it should be possible to bundle your SQLite DB with a ClickOnce application. You would get other benefits (if you are interested) such as automatic updates.
The problem also occurs if you changed the namespace of App.xaml.cs, but not of App.xaml. The moment you add the code above, you will know, since the InitializeComponent() call will not compile.