|
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.
|
|
|
|
|
While writing to an excel file(Console Application), a message box appears 'Do you want to save the changes ..........'. How can i avoid this type of popup windows while writing to?
|
|
|
|
|
Try this
Excel.Application eApp = new Excel.Application();
eApp.DisplayAlerts = false;
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hello
When try to send a ref of array string to the variant pointer we get DISP_E_TYPEMISMATCH exception.
Eg:
MFC App is OLE Automation enabled.
void Funct1(VARIANT *pVar)
from C# side we invoke this as follows
string [] str = new string[100];
Object obj = (Object) str;
mfcAutoApp.Funct1(ref obj);
Any suggestions on this...
-thanks
|
|
|
|
|
Any suggestions...???
|
|
|
|
|
Resolved the issue using VariantClass helps things work smoothly...thanks for all your time.
|
|
|
|
|
Is there a method to create a new font,which we can define the ratio of font height and width?
like the font in autoCad.
from vevi
|
|
|
|
|
I use the GraphicsPath's drawString method.
and use the Matrix to set the font's ratio of height and width.
...it can do it,but too complex to implement.
is there a simple method to implement it ?
from vevi
|
|
|
|
|
I have a pointer to a struct. In C++ I can allocate and deallocate it but in C#, I can't. Could you give me a solution plz !
|
|
|
|
|
For example I have a struct like this :
public unsafe struct V
{
unsafe public V* backpointer;
};
When I declare :
V n = new V();
n.backpointer = &x
in a loop then the previous value of backpointer changed.
Could you plz help me ?
modified on Sunday, October 5, 2008 9:50 PM
|
|
|
|
|
I think that the garbage collector deallocated the memory. How can we stop it plz ?
|
|
|
|
|
hockymot2008_2009 wrote: I think that the garbage collector deallocated the memory.
No, it didn't, as you never allocated any memory from the heap.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hockymot2008_2009 wrote: V n = new V();
That doesn't do what you think that it does. As the struct is a value type, you are not allocating memory for an object, you are just creating a struct value. The value is assigned to the struct n, and will overwrite the previous value in the struct.
Is there any reason why you are trying to use structs instead of classes and pointers instead of references?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Use the fixed[^] keyword. More about unsafe code[^].
By the way, you don't need a second unsafe keyword inside another unsafe. And you don't need a semicolon after a struct or class declaration.
public unsafe struct V
{
public V* backpointer;
}
Eslam Afifi
|
|
|
|