|
U can just use a simle java script for that.
Vipin
|
|
|
|
|
Vipin Venugopal wrote: U can just use a simle java script for that.
<input type=text name=txtPostalCode removed="if(!isNS4){if(event.keyCode > 45 || event.keyCode > 57) event.returnValue = false;}else{if(event.which < 45 || event.which > 57) returnfalse;}">
What?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Thnax for all the input peeps..I am going to try the Int32.TryParse..Btw, what is the best resource for knowing all in the classes and methods ( other than MSDN help )? I don't expect to know them all, but it would be good to have a good reference other than Google...
And Judah's reponse is for keytrokes that are between 0-9, correct?
Jude
|
|
|
|
|
Ahhh..I am using 2003...Int32.TryParse i not available for 1.1, and 2003 doe not support 2.0 from what I know, Corret?
Jude
|
|
|
|
|
Try this.
text box's KeyPress event
if ((int)e.KeyChar >= 48 & (int)e.KeyChar <= 57)
OR
in KeyDown or KeyUp event
if (e.KeyCode >= Keys.D0 & e.KeyCode <= Keys.D9)
this.Text = e.KeyValue.ToString();
Best of Luck.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
hi
i want to print my datagrid records but it's more than one page . how to print it to multipage ?
|
|
|
|
|
Hi,
I have a question related to passing an array to a method.
In C++, if I have an array Arr[] with 20 elements, and I want to pass the array to a method, but starts from the 10th element, then I would do the following:
AMethod(Arr + 10);
If I want to do the same thing in C#, what would be the proper way? Thanks a lot.
|
|
|
|
|
Pass the offset and length. It is always a good practice.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Use the System.ArraySegment generic class.
|
|
|
|
|
Friends,
In Winforms, the control gets highlighted when it has an input focus either by pressing TAB key or by clicking it with mouse. Now what i want is that my button control should not get highlighted when it has an input focus. How can i do so ? Is there any property ?
Imtiaz
|
|
|
|
|
You can create such a button by setting the ControlStyles.Selectable value to false.
This is a sample of how to do it (#using directives omitted):
public class InertButton : Button
{
public InertButton()
{
SetStyle(ControlStyles.Selectable, false);
}
} That's it.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
i´m develop a local and remote application with sqlServer, the connection path where i´ve ip address, database, user and pass its on xml file, with two differents tags <local> and <remote>, and my question is, how its better, a class user with and attribute state , 0 local ,1 remote and when i use the class DataBase management if (i==0){read XML Local}else{read XML remote},or use a factory ?? and it i use a factory how can i do???
thanks for all
see you soon
|
|
|
|
|
I need to write some decimals on magnetic medium.
A C# decimal is realized in memory as series of 16 bytes.
How can I, without unsafe mode, code the conversion from deciamal into such an array byte[] and backwards?
HilSoft
|
|
|
|
|
If you use Reflector, you can see what the underlying implementation is for Decimal . For instance, there's an internal method called GetBytes that looks like this:
internal static void GetBytes(decimal d, byte[] buffer)
{
buffer[0] = (byte) d.lo;
buffer[1] = (byte) (d.lo >> 8);
buffer[2] = (byte) (d.lo >> 0x10);
buffer[3] = (byte) (d.lo >> 0x18);
buffer[4] = (byte) d.mid;
buffer[5] = (byte) (d.mid >> 8);
buffer[6] = (byte) (d.mid >> 0x10);
buffer[7] = (byte) (d.mid >> 0x18);
buffer[8] = (byte) d.hi;
buffer[9] = (byte) (d.hi >> 8);
buffer[10] = (byte) (d.hi >> 0x10);
buffer[11] = (byte) (d.hi >> 0x18);
buffer[12] = (byte) d.flags;
buffer[13] = (byte) (d.flags >> 8);
buffer[14] = (byte) (d.flags >> 0x10);
buffer[15] = (byte) (d.flags >> 0x18);
}
You could use reflection to call that internal method or you could use GetBits and convert the integers to bytes yourself. Here's what GetBits looks like:
public static int[] GetBits(decimal d)
{
return new int[] { d.lo, d.mid, d.hi, d.flags };
}
To convert the bits back into a Decimal , you can use the constructor that takes an int array. The array is in the same format that is output by GetBits .
Logifusion[^]
|
|
|
|
|
I do not know what is Reflector,
and what the function .lo .mid and so on
My Visual Studio 2005 does not understand such kind of things.
But thank you, anyway. I'll try...
HilSoft
|
|
|
|
|
Reflector is a tool that decompiles IL and shows the (approximate) source that was used to create it. lo, mid, etc are private members of the Decimal class.
http://www.aisto.com/roeder/dotnet/
|
|
|
|
|
Even if it is so, I have no rights to use any private members of the Decimal class. The code will be aborted.
HilSoft
|
|
|
|
|
The public GetBits method returns the internal contents as 4 ints. The reflected code shows how the data goes into them. You can then bust the ints into seperate bytes for your own purposes. Alternately using features provided in the System.Reflection namespace you can access and use the private GetBytes method the same way Reflector does.
|
|
|
|
|
Thank you very much, Dan. As I understood you, I can write:
int[] ints4= Decimal.GetBits(dec);
And then I can put each "int" of the ints4 into corrspondent part of an 16-byte-array.
As I know, I can use for the purpose the BitConverter function. Isn't it?
I've wrote
using System.Reflection;
but I do not know what to write on...
(The Reflector.zip I've downloaded from Lutz Roeder. Thank you, it is useful).
And the Problem remains - how to OBTAIN decimal even if I have the ints4 (the backwards task).
-- modified at 16:21 Thursday 27th July, 2006
|
|
|
|
|
decimal d = new decimal(1234.5678);<br />
byte[] b = System.Text.Encoding.UTF8.GetBytes(d.ToString());<br />
string s = System.Text.Encoding.UTF8.GetString(b);<br />
d = Convert.ToDecimal(s);
only two letters away from being an asset
|
|
|
|
|
It's fantastic! Thank you.
But I'm not too fond to use such kind of heavy operations like converting to strings and bachwards.
It is much better than to be asset, but is far from natural.
Thank you, anyway!
HilSoft
|
|
|
|
|
I am new in C# and nobody could clarify this:
Yesterday I created some kind of an observer pattern
I created a delegate and two combo boxes, in one I set an event for changes using the delegate and in the other one I "listen" to that event. This works great, whenever the cahnge occurs in the first combo, the second one adjusts itself accordingly. The problem is if I didn't set a listener yet I get a null object exception for the line where I fire the event. Is this normal or am I doing something wrong ? To solve the problem I verify first if the object is null but I want to be sure I am not doing something stupid
Here is the code (useless lines removed)
public class CountryCombo : ComboBox
{
public event CountryChangedHandler countryChanged;
...code
public CountryCombo() : base()
{
...code
this.Leave += new EventHandler(CountryCombo_Leave);
this.BindingContextChanged += new EventHandler(CountryCombo_BindingContextChanged);
}
void CountryCombo_BindingContextChanged(object sender, EventArgs e)
{
this.countryChanged(SelectedValue.ToString()); //********* This where the error occurs if no listener
//********* this.countryChanged is null
}
void CountryCombo_Leave(object sender, EventArgs e)
{
if (this.SelectedIndex == -1 | this.SelectedIndex == 3)
{
this.SelectedIndex = 0;
}
this.countryChanged(SelectedValue.ToString());
}
}
public delegate void CountryChangedHandler (string countryISO3);
public class ProvinceCombo : ComboBox
{
...code
public ProvinceCombo(CountryCombo combo) : base()
{
combo.countryChanged += new CountryChangedHandler(ChangeCountry);
...code
}
public void ChangeCountry(string iso3)
{
...code
}
}
|
|
|
|
|
~~~Johnny~~~ wrote: To solve the problem I verify first if the object is null but I want to be sure I am not doing something stupid
Nope, it's not stupid. It's what you're supposed to do. Check if countryChanged is null before firing an event on it.
Logifusion[^]
|
|
|
|
|
Can you summerize the logic behind that?
|
|
|
|
|
You declare this:
public event CountryChangedHandler countryChanged;
countryChanged becomes a field in your class. But what does it store? Behind the scenes, countryChanged is actually a reference to a linked list of delegates that subscribed to the event. Initially, the field references null because there are no subscribers. The delegate CountryChangedHandler is actually an item in a linked list, meaning that within it is a pointer to the next item. So, when you subscribe to the event, a new CountryChangedHandler is created and added to end of the linked list. The reason Microsoft decided to do this was because it's a very efficient way to manage all the subscribers to a particular event. What it means for us is that you have to check if the event field is null before firing.
Logifusion[^]
|
|
|
|