|
TNX Tom
Application.Executable Path solved my problem is there any disadvantage to doing things this way?
|
|
|
|
|
Not at all. If you use Reflector[^] you can view the code for this property. Internally, it uses GetEntryAssembly(), but also handles other cases. So Application.ExecutablePath would probably be the best way to go.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
This is why you never write code that uses the "current" directory. You ALWAYS write your code to generate fully qualified path names when working with files.
|
|
|
|
|
Hy
Can anybody tell me what is the difference between KeyPress event and OnKeyPress override? Why we need both? Why don't work in the same time, only one run?
thx
|
|
|
|
|
The KeyPress event can be used by the associated class or other classes. For example, a Form can listen for key pressed on a TextBox that it contains. The OnKeyPress method is used to fire the KeyPress event. This can only be used by dervied types. So if you create a custom TextBox (say MyTextBox), then you can override the OnKeyPress to catch key presses, alter when the KeyPress event is fired, fire another event, etc.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hello,
Way 1)
OnKeyPress ist the virtual method of a class, which can be overriden from an inherited class.
Way 2)
For handling the KeyPress event, you do not have to inherit a class.
You instanciate a class and handle the delegate.
All the best,
Martin
|
|
|
|
|
Hi,
I am currently writing an application that will dynamically load different applications and contain them in its own form (its an MdiManager Form). A big issue that I am running into is as follows:
When my main application loads and constructs another program, the child program is blowing up because the ConfigurationManager is using the main containing application's app.config. What I can't find....How in a dynamic environment do I get the current application's resulting exe name.
All of these classes are returning the name of the containing application:
Application.ProductName
Assembly.GetEntryAssembly().GetName().ToString()
I am trying to avoid hard coding "MyClass.exe.config" into each child application. I would much rather find a new method that I could use from now on instead of relying just on the ConfigurationManager. Thanks
|
|
|
|
|
You could get the path to the child application like so (assuming that the Program class below is in your child application):
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static String GetPath() {
Assembly assembly = Assembly.GetExecutingAssembly();
return System.IO.Path.GetDirectoryName(assembly.Location);
}
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Sorry, you can get the EXE name like so:
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static String GetExeName() {
Assembly assembly = Assembly.GetExecutingAssembly();
return System.IO.Path.GetFileName(assembly.Location);
}
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi friends,
My Requriment is When The Keyboard Left Key Is pressed it Works Like A BackSpace Key.
how to write a code in c#.
plz help me.asap.
regards
venkat.
venkat
venkat
|
|
|
|
|
Quick and dirty:
Setup a form with a text box
Add an event to that TextBox for the KeyDown event
Check if the key presses is Keys.Left
If so:
textBox1.text = textBox1.Text.Remove(textBox1.Text.Length - 1)
|
|
|
|
|
Quick and dirty:
Setup a form with a text box
Add an event to that TextBox for the KeyDown event
Check if the key presses is Keys.Left
If so:
textBox1.text = textBox1.Text.Remove(textBox1.Text.Length - 1)
|
|
|
|
|
Hello Friends,
Sealed cannot be inherited but it enables the run-time optimizations
Can anybody specify or explain this point
Thnx
.............
|
|
|
|
|
If you have a class that you don't want somebody to be able to inherit from, mark it as sealed. As the class is marked as sealed, the optimizer can perform certain optimizations such as transform virtual function member invocations into non-virtual invocations.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thnx ..
But can u explain it more with example .........
|
|
|
|
|
Why? I've explained it and now you have enough information to look it up on google. It's your friend, so use it.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Why is it all these people treat Google like it's the "secret ingredient" that no experienced developer ever mentions in their problem solving recipe??
|
|
|
|
|
I guess that Google's marketing isn't up to much because these idiots seem to have never heard of it.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I don't know who voted you a one for that. But I've countered it.
|
|
|
|
|
Thanks. I hope it wasn't the marketing guys at Google.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Well which part don't you understand?
With a normal class you can inherit it.
If you mark a class as sealed you can't inherit it.
Because the compiler knows it won't be inherited there are probably run-time optimizations that can be performed that wouldn't work if the class was inherited.
|
|
|
|
|
If you are developing components for third-party developers, then you can use sealed classes to prevent them from deriving from your components. Off the top of my head I can think of two reasons for doing this.
1. Quailty Assurance Time - If your class supports being derived, then you should really test it and make sure there are not any problems.
2. Support Time - If you allow your class to be derived, then you will inevitably get support requests.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
The others have posted good answers, but I'll mention that you shouldn't use sealed very much. Every once in a while I'll come across a class from which I want to derive, but is sealed, leaving me wondering, "Why the heck did they seal it? No harm can come from my extending it."
I just took a look in my largest solution, which includes my main library, and found that 56 of 309 classes (18%) are sealed, most of them are in the set: { EventArgs , Attribute , Form }
I suggest you not throw sealed on every class you write.
|
|
|
|
|
Hello,
I am reading some settings from config file and save back in case of any modification.
I am restarting the application by Application.Resatart() to read all the settings if modified.
The problem is that while restarting the application it comes to Form_closing event only once abd don't kill the main process as well.
So next time u are restarting the application it won't come to the Form_closing event again.
I need to terminate some threads in closing events.... So how should i do it???
Is their any other way to restart the application???
Thanks.
|
|
|
|
|
What if you hold a boolean that states IsRestart
than instead of Application.Restart() you put Close()
And in the closing event you do your stuff and you check the IsRestart
if true, than do Application.Restart()
Try it out, because i am not sure if it will work.
|
|
|
|