|
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
|
|
|
|
|
You can save font as string and read it later as an object using FontConverter.
I've used the following code before to serialize font.
private Font _font;
public string FontString {
get { return _font.Name + ", " + _font.SizeInPoints + "pt, " + "style=" + _font.Style; }
set { _font = (Font)new FontConverter().ConvertFromString(value); }
}
|
|
|
|
|
tnx Lazy_Monk .It seem to be good idea for save font.
Do you have any idea if we have another object that may be have more properties?
sepel
|
|
|
|
|
The principle is the same. You have to serialise it into something that you can save as an independent chunk of data.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
sepel wrote: 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.
You can neither save images nor files in a database. An images is converted into a byte array before it's saved in the database. The contents of the file is read as a byte array before it's saved in the database.
It's the same with a Font object. You can't save the object in the database, you have to take the information from the object and package as data that can be saved in the database.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|