home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / InfoPath.en-us / InfLR.cab / FL_RestrictaControl_sAcceptableKeystrokes__142710_ENU____.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Extensible Markup Language  |  2008-09-17  |  2KB  |  70 lines

  1. <?xml version="1.0"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.   <CodeSnippet Format="1.0.0">
  4.     <Header>
  5.       <Title>Restrict a Control's Acceptable Keystrokes</Title>
  6.       <Author>Microsoft Corporation</Author>
  7.       <Description>Overrides the default ProcessCmdKey function of a Windows Forms Control and restricts user input to numeric and navigation keys.</Description>
  8.       <Shortcut>formRestrict</Shortcut>
  9.     </Header>
  10.     <Snippet>
  11.       <References>
  12.         <Reference>
  13.           <Assembly>System.Drawing.dll</Assembly>
  14.         </Reference>
  15.         <Reference>
  16.           <Assembly>System.Windows.Forms.dll</Assembly>
  17.         </Reference>
  18.         <Reference>
  19.           <Assembly>System.dll</Assembly>
  20.         </Reference>
  21.       </References>
  22.       <Imports>
  23.         <Import>
  24.           <Namespace>Microsoft.VisualBasic</Namespace>
  25.         </Import>
  26.         <Import>
  27.           <Namespace>System.Drawing</Namespace>
  28.         </Import>
  29.         <Import>
  30.           <Namespace>System.Windows.Forms</Namespace>
  31.         </Import>
  32.         <Import>
  33.           <Namespace>System</Namespace>
  34.         </Import>
  35.       </Imports>
  36.       <Declarations>
  37.         <Literal>
  38.           <ID>baseClass</ID>
  39.           <Type>String</Type>
  40.           <ToolTip>Replace with the type of the class you want to restrict.</ToolTip>
  41.           <Default>ComboBox</Default>
  42.         </Literal>
  43.         <Literal>
  44.           <ID>restrictedControlClass</ID>
  45.           <Type>String</Type>
  46.           <ToolTip>The name of the derived class.</ToolTip>
  47.           <Default>restrictedComboBoxClass</Default>
  48.         </Literal>
  49.       </Declarations>
  50.       <Code Language="VB" Kind="type decl"><![CDATA[Class $restrictedControlClass$
  51.     Inherits $baseClass$
  52.     Const WM_KEYDOWN As Integer = &H100
  53.  
  54.     Protected Overrides Function ProcessCmdKey _
  55.         (ByRef msg As Message, _
  56.         ByVal keyData As Keys) As Boolean
  57.  
  58.         If msg.Msg = WM_KEYDOWN Then
  59.             Return Not ((keyData >= Keys.D0 And keyData <= Keys.D9) _
  60.                 Or keyData = Keys.Back Or keyData = Keys.Left _
  61.                 Or keyData = Keys.Right Or keyData = Keys.Up _
  62.                 Or keyData = Keys.Down Or keyData = Keys.Delete
  63.         End If
  64.         Return MyBase.ProcessCmdKey(msg, keyData)
  65.     End Function
  66. End Class
  67. ]]></Code>
  68.     </Snippet>
  69.   </CodeSnippet>
  70. </CodeSnippets>