|
I haven't tried, but I think this will do the trick
Application.ThreadException += ThreadExceptionHandler;
Application.Run(new Form1());
Application.ThreadException -= ThreadExceptionHandler; Application.Run blocks until application exits.
|
|
|
|
|
In case that some kind of unexpected error occurs inside Form1, if program execution transfer to our Exception handler, and handler EXIT application (because some kind of fatal error has occurred), does program executes code after "Application.Run(new Form1());"???
|
|
|
|
|
Well, wrap it in a try finally blocks
Application.ThreadException += ThreadExceptionHandler;
try{
Application.Run(new Form1());
}
finally{
Application.ThreadException -= ThreadExceptionHandler;
} finally block will execute always.
|
|
|
|
|
I'm not sure that's needed -- if an exception is thrown by the app and not handled, it's going to hit your error handler anyway.
I may, of course, be wrong.
Cheers,
Vıkram.
"You idiot British surprise me that your generators which grew up after Mid 50s had no brain at all." - Adnan Siddiqi.
|
|
|
|
|
Correct. But we were talking about detaching event handler when application ends. So I think finally is required.
|
|
|
|
|
The operating system is perfectly capable of cleaning up when your process exits.
Actually, .NET will already clean up all objects (including the event handler) when the AppDomain shuts down.
It only makes sense to explicitly detach the event handler when your application doesn't shut down but you still want to free the memory used by the exception handler.
|
|
|
|
|
Daniel Grunwald wrote:
The operating system is perfectly capable of cleaning up when your process exits.
It's perfectly clear, but, why MSVS documentation caution me that I " must detach your(mine) event handlers when your(my) application is disposed, or memory leaks will result."
matix
|
|
|
|
|
You could unload only the AppDomain that caused the exception, for example.
|
|
|
|
|
Hi All,
I want to paste only valid value(like numeric value) in textbox through mouse(right click) and keyboard(Ctrl+V).
Thanks in advance.
|
|
|
|
|
Have you tried anything yet?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
No, I do not understand how to do it?
|
|
|
|
|
|
Handle the TextChanged event.
Even better, use a NumericUpDown control.
Cheers,
Vıkram.
"You idiot British surprise me that your generators which grew up after Mid 50s had no brain at all." - Adnan Siddiqi.
|
|
|
|
|
override WndProc, trap WM_PASTE and process there. Check out pinvoke.net.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thanks, but I don't know how to use this. Please give me a little example.
|
|
|
|
|
OK. This example creates a customized TextBox so add this class, build then drop onto a form.
public class RestrictedTextBox : TextBox
{
private const int WM_PASTE = 0x0302;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_PASTE)
{
if (!IsPasteValid())
{
m.Result = IntPtr.Zero;
return;
}
}
base.WndProc(ref m);
}
private bool IsPasteValid()
{
bool rtn = false;
IDataObject obj = Clipboard.GetDataObject();
string pasteString = (string)obj.GetData(typeof(string));
return rtn;
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
If that's a web application or windows application . If it's a web application, then you can go about by Javascripts.
|
|
|
|
|
|
I think, this piece of code will help you out...
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ( Convert.ToInt16(e.KeyChar) >= 48 && Convert.ToInt16(e.KeyChar) <=57)
{
e.KeyChar = e.KeyChar;
}
else
{
e.KeyChar = Convert.ToChar(0);
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
char[] strSample = new char[((System.Windows.Forms.TextBox)(sender)).Text.ToString().Length];
strSample = (((System.Windows.Forms.TextBox)(sender)).Text).ToCharArray();
for (int i=0; i<strSample.Length;i++)
{
if (Convert.ToInt16(strSample[i]) >= 48 && Convert.ToInt16(strSample[i]) <= 57)
{
continue;
}
else
{
((System.Windows.Forms.TextBox)(sender)).Text = "";
break;
}
}
}
Try this and let me know if you have any concerns.
Regards,
Vengat P
|
|
|
|
|
Thanks Vengat, Everything is worked fine but if we paste characters then textbox goes blank. In that case we want current value of textbox. Then how to do that.
|
|
|
|
|
I am also new to windows application, but i'm sure that, you can bind the value of textbox again with the help of a global variable(that will be updated for each key press event and text change event).
Sample:
private string strTestVal = string.Empty;
on keypress event:
in if condition
strTestVal = textBox1.Text.ToString();
on text change event:
textBox1.Text = strTestVal;
Regards,
Vengat P
|
|
|
|
|
Hi Anyone.
Is there a way to save and reterive system.font in sql Databse?
sepel
|
|
|
|
|
There is no such class. Do you mean the System.Drawing.Font class?
You can't save objects in the database. Save the information that you need to recreate the Font object.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: There is no such class. Do you mean the System.Drawing.Font class?
yes i want to save a font for each control (for example: textbox).
i think there should be a solution for it .as same as we save image or file in database.
sepel
|
|
|
|