As explained here I have built a sample console application in which I change the culture in the Main function. It works well.
Now, building another sample winform application, I wonder where would be the best place to put this
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture ("en-US");
Thread.CurrentThread.CurrentUICulture=new CultureInfo("en-US");
If I put this in the constructor of a Form1, will this apply to all operations in this class?
What if this Form1 opens another form Form2 and an exception occurs there?
What if Form1 uses another class Class1?
I am willing to experiment in this, but if someone has an answer based on previous knowledge, I appreciate to hear it.
For a winforms application put things that deal with the context of the entire application in program.cs and be done with it.
If I put this in the constructor of a Form1, will this apply to all operations in this class?
What if this Form1 opens another form Form2 and an exception occurs there?
What if Form1 uses another class Class1?
All your other concerns are irrelevant, and are sereverly overthinking the problem.
Note : The best way to learn programming windows or any other language is to read as much as you can. Microsoft have everything documented always go straight to the source.
Some additional reading for you
Thread.CurrentUICulture Property
Thread.CurrentCulture Property
Initialization code in a WinForms App - Program.cs or MainForm?
Related
I have created a taskbar application that I want to ensure that one and only one instance is running. In an article called, WPF Single Instance Best Practices, Evan Wondrasek posted a great answer and I have added it to my application. This appears to work really well with one small exception.
When I implemented this I have lost my splash screen and I do not know why. Can anyone explain why my splash screen no longer works and how I might get the splash screen working again? I used a simple PNG file and marked its properties as a SplashScreen. I am beginning to think I may need to do something with the SplashScreen class to fix this.
TIA, Doug
By implementing the answer in the link you supplied, you replaced the Main function & startup object of your application. You will need to create the SplashScreen object yourself now, put this inside your own Main method:
SplashScreen splashScreen = new SplashScreen("images/logo.png");
splashScreen.Show(true);
See this link for more information: http://social.msdn.microsoft.com/Forums/vstudio/en-US/33894287-101a-4c9f-8c6a-f0452ab4ced0/splash-screen-not-displaying-anymore-on-startup?forum=wpf
I’ve created a winform application with lots of forms, (in mdi and dialog)
but every time a close a form it stays in the memory,
so I would like to use de .Dispose() option.
but I don’t want to add this code to ALL of the forms,
I just want to place one code that’s activates on a FormClose command,
can i use en override.onFormClose command?
and where in the application do I put this code,
I tried it at the MDI form, but without success
Thanks,
Bram
ps
i'm using DevExpress components
If you call GC.Collect() and the forms are still in memory, then it is because there is a reference held to them somewhere.
You need to trace all references and make sure they are being released.
Craete a separate base class, implement your dispose method, and then inherit all forms from this class
I want to show an loading image when i launch my desktop application. can anybody tell me how to show this in C#? Results required as happens in visual studio 2005/2008 when we launch this application.
What you are looking for is actually a splash screen. Look at this codeproject article. It explains really well how you should do this.
http://www.codeproject.com/KB/cs/prettygoodsplashscreen.aspx
What i did in my previous project was, that make the Form1 (display form) and make it wait for a while, then close it after that launch the Form2 which is the actual application.
But that was way back when i was a fresher. Now what i might do is, have a Form1 which ill launch and in the backgroundworker do all major UI processing work such as if any loading of data needs to be done, etc stuffs and keep every thing ready in memory. Then ill close the Form1 or make it hide or invisible and launch the Form2 which is the main app form and pass all the information required to it.
I have a application in which i have several forms. In that forms, I have a System Settings form. I have to open this form from the menu as well as a shortcut created on the desktop.
I am able to open the form from 2 places individually. But the problem is, It's opening two separate instance of the same form. it means, first, i have clicked on menu to open the form.Now my Form instance is created and it is displayed on the screen. But whenever i click on my desktop icon, It's creating another instance of the same form instead of displaying the same form. . So it means it's displaying two instances of the same form.
But i have display one form only. I have tried and googled in the net also. I didn't find any information.
Can anybody please help me to fix this issue. Any kind of suggestion will be really helpful to me.
You need a single instance. This construct is already available within the .Net framework. Just check out this post from Hanselman.
Note: I know that the namespace of this class is VisualBasic. But that shouldn't hinder you to use it in your C# application. It's just the name of a namespace. It doesn't meant anything about its functionality. (Microsoft had it better named Foo. In that case it would be much more popular.)
Sounds to me, that you need a mutex to control that only one application instance is running at a given time.
See http://iridescence.no/post/CreatingaSingleInstanceApplicationinC.aspx for further details
You have to implement some kind of locking mechanism to allow only one instance of your program running. I guess your System Settings program could check if other instances are running on computer on program launch, if so terminate, otherwise start a new instance.
To throw in one more link, this post seems to cover (my understanding of) what you are trying to do.
http://dotnetperls.com/single-instance-windows-form
I have used semaphor concept to control this. Whenever the form is opened i am writing an entry into registry. Once the form is closed i am removing this entry.
So, whenever i try to open the form, it will check the registry entry. Based on that it will open the form.
Sounds like you need a modified version of the Singleton design pattern. Try having a public static method within the class that internally calls the constructor for the form. Then as someone suggested use a counter variable to keep track of how may times that static method is called thus giving you a metric you can use to ensure only the desired number if instance are created.
Hey, I have been searching on google and I cant seem to find anything about targeting different windows in c#, I am using Visual studio 2010.
I'm not sure how to do this but I'm pritty sure it can be done, does anyone know where I can read up about it?
I need to be able to target a different program (like notpad for example), and simulate a key press.
Thanks.
If you mean interacting with different windows (possibly part of a different process), typically you would get a window handle (can be done in many ways), and then you can send messages and get data from those messages to those window handles.
For example see SendMessage which you would p/invoke from your C# app.
If you want to get updates on when certain events happen in those windows then you can use Windows Hooks.
I'm going to assume you're on WinForms (same applies for WPF, slightly different code though).
In your project you have
Form1
Form2
Form3
At the top of your Form1 class, you define this code:
Form2 frm2;
Form3 frm3;
Assuming Form1 is your startup object you add buttons for "Show Form2" and "Show Form3"
In their respective code-behind you add code like this
frm2 = new Form2();
frm2.Show();
frm3 = new Form3();
frm3.Show();
Same concept applies for WPF. If you're trying to do stuff with a window outside your application, the SendMessage Windows API is probably what you need to look into.