My EnableVisualStyles() is not working anymore. I now get forms with a green line around it, it's horrible. How can I fix this? When I start a new project it's the same. I think about un-installing visual studio and reinstall it, but there should be a better way I think/hope. Does anyone know the solution?
PS I tried the Application.DoEvents() method, but this is not the answer for me.
an example of how my form looks now
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Related
I have a regular button (or any other control), which at design time looks 3D like this:
And at runtime looks flat like this:
Of course I want it to look 3D, but I can't see any reason, option or property to make it 3D. I thought that maybe it's a .NET issue, but even targeting .NET 4.5.3 didn't help.
P.S: Obviously I have windows 7, so this can't be the issue
Normally, the Application.EnableVisualStyles() method is called by default in the static void Main() method, inside the program.cs file. Maybe you're maintaining an older app, or someone removed that line at some point. Check to see if it's missing.
static class Program
{
[STAThread]
static void Main()
{
// Enable visual styles for your application.
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
Technically, you can call that method from anywhere in your application, but then controls that have already been drawn may retain the older "flat" look. Best to leave it in the program.cs file, and execute it before you start up the message loop for your application.
Add this code into Form_load() :
private void Form1_Load(object sender, EventArgs e)
{
button1.FlatStyle = FlatStyle.Standard;
}
Application.EnableVisualStyles();
is what you need to add to program.cs
I know this may have been answered, but I just can't find a suitable answer. Any idea how to show more than one Windows Form?
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main());
Application.Run(new MenuModule());
}
By declaring two Application.Run, the the Windows Form will show after I exit the first.
When you use that overload of Application.Run it will block until the form you passed has closed.
You could try:
new Main().Show();
new MenuModule().Show();
Application.Run();
This will run until you call Application.Exit even if both forms have been closed. So a better option might be:
new MenuModule().Show();
Application.Run( new Main() );
Which will cause the application to exit after the Main form has closed, regardless of the status of the MenuModule form.
As an option you could also have the Main form show the second one, that'll work too.
you can create an object in 'Main' class (form) contractor.
public main(){
.
.
.
new MenuModule().show();
.
.
.
}
my image "Input1GreenLight" needs to be visible when my FormCall thread method is called. However, in my "while (true)" infinite loop, I call the class Form1.setLights(), which calls the method in the Form1.cs, but I can not access Input1GreenLight as it says "this member can not be reference from a static context".
So I realize the issue, but I'm not sure how to fix/address it, suggestions appreciated and please find code snippets below (please keep in mind, FormCall is being called through a new thread, and thus is not blocking my program). Also, do not mind GlobalVars.Input1, that is being used by a separate piece of code.
Code from my C# Script
public static void FormCall()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
while (true)
{
Form1.setLights();
}
}
Code from my Form1 Script
public static void setLights()
{
Input1GreenLight.Visible = GlobalVars.Input1;
}
Input1GreenLight is the picturebox's name, just to clarify again. I am new to C#, familiar with C/C++. Thank you in advance
I have a Windows forms application, and for some reason I'm getting an invocation error on application.run form1 why would this be? I have been scratching my head all day
namespace UserDataImport
{
class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
I'm getting a Target invocation error
start debugging the program, on the VS press Debug->Exception. that will open a window like this:
mark the "common Language Runtime Exceptions"
now when the exception is thrown you should have a nicer look at what went wrong. then add the code that went wrong
I can find many examples on how to get arguments in a console application, but I can't seem to find an example of how to get arguments in a windows form application.
I would like to following things.
whenever I open a jpg file, windows launches my application.
I would like to know path and name of the jpg file from my application.
How do i do that?
Environment.GetCommandLineArgs
Open up program.cs, on a file > new > winform project, you'll get
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
change this to
static class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
Now its just like the console apps, you'd access them via args.
Even if you don't go with this option, you should be aware of how the win form app is initialized :) This way, you could run different forms or not run a form at all.