Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Cell_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Decimal)
- void CellText_KeyUp(object sender, KeyEventArgs e)
- {
- var DecSep = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;
- if (e.Key == Key.Decimal && DecSep != ".")
- {
- if (e.OriginalSource is TextBox)
- {
- var TB = (TextBox)e.OriginalSource;
- string sText = TB.Text;
- int iPos = TB.SelectionStart - 1;
- if (iPos >= 0)
- {
- System.Diagnostics.Debug.Assert(sText.Substring(iPos, 1) == ".");
- TB.Text = sText.Substring(0, iPos) + DecSep + sText.Substring(iPos + 1);
- TB.SelectionStart = iPos + 1; // reposition cursor
- }
- }
- }
- }
- <html>
- <heaD>
- <script language="javascript">
- function keypress1 ()
- {
- var e=window.event || e
- unicode = e.charCode ? e.charCode : e.keyCode;
- if (unicode==46)
- { return (e.charCode ? e.charCode=44 : e.keyCode=44); }
- }
- function keypress2 ()
- {
- var e=window.event || e
- unicode = e.charCode ? e.charCode : e.keyCode;
- if (unicode==46)
- { return (e.charCode ? e.charCode=46 : e.keyCode=46); }
- }
- function keyDown(e){
- if (!e){
- e = event
- }
- var code=e.keyCode;
- if(code==110)
- return document.onkeypress=keypress1
- else if(code=188)
- { document.onkeypress=keypress2 }
- }
- document.onkeydown = keyDown
- </script>
- </head>
- <body>
- <input type=text>
- </body>
- </html>
- public class NumericUpDown : System.Windows.Controls.NumericUpDown
- {
- [DebuggerStepThrough]
- protected override double ParseValue(string text)
- {
- text = text.Replace(".", Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
- return base.ParseValue(text);
- }
- }
Add Comment
Please, Sign In to add comment