/[RomCheater]/trunk/Win32/libWin32/Win32/UI/NumericBoxBase.cs
ViewVC logotype

Diff of /trunk/Win32/libWin32/Win32/UI/NumericBoxBase.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/Win32/libWin32/Win32/UI/NumericBoxBase.cs	2012/06/02 12:05:01	222
+++ trunk/Win32/libWin32/Win32/UI/NumericBoxBase.cs	2012/06/02 13:20:13	223
@@ -6,6 +6,7 @@
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
+using System.Collections;
 
 namespace System.Windows.Forms
 {
@@ -40,6 +41,48 @@
 
         private void btnCopy_Click(object sender, EventArgs e) { Clipboard.SetData(DataFormats.Text, this.Text); }
         private void btnPaste_Click(object sender, EventArgs e) { if (this.ReadOnly) return; this.Text = (string)Clipboard.GetData(DataFormats.Text); }
+
+
+        protected void CreateStandardKeys(List<Keys> ValidKeys)
+        {
+            // these are mostly editing/navigation keys
+            ValidKeys.Add(Keys.Delete);
+            ValidKeys.Add(Keys.Back);
+            ValidKeys.Add(Keys.Up);
+            ValidKeys.Add(Keys.Down);
+            ValidKeys.Add(Keys.Left);
+            ValidKeys.Add(Keys.Right);
+            ValidKeys.Add(Keys.Home);
+            ValidKeys.Add(Keys.End);
+        }
+        protected virtual void CreateValidKeys(List<Keys> ValidKeys) 
+        {
+            //ValidKeys.AddRange(Enum.GetValues(typeof(Keys)).Cast<Keys>().Where(x => x >= Keys.D0 && x <= Keys.D9));
+           // ValidKeys.AddRange(Enum.GetValues(typeof(Keys)).Cast<Keys>().Where(x => x >= Keys.NumPad0 && x <= Keys.NumPad9));
+        }
+        protected List<Keys> GetValidKeys()
+        {
+            List<Keys> ValidKeys = new List<Keys>();
+            CreateStandardKeys(ValidKeys);
+            CreateValidKeys(ValidKeys);
+            return ValidKeys;
+        }
+        private void txtValueBox_KeyDown(object sender, KeyEventArgs e)
+        {
+            List<Keys> ValidKeys = this.GetValidKeys();
+            if (ValidKeys.Contains(e.KeyCode))
+            {
+                if (txtValueBox.Text.Contains(".") && (e.KeyCode == Keys.Decimal || e.KeyCode == Keys.OemPeriod))
+                {
+                    e.SuppressKeyPress = true;
+                }
+                return;
+            }
+            if(!e.Control && !e.Alt)
+            {
+                e.SuppressKeyPress = true;
+            }
+        }
     }
 
     #region NumericBox Extensions

 

  ViewVC Help
Powered by ViewVC 1.1.22