<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:inherit;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML \00D6nceden Bi\00E7imlendirilmi\015F Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLncedenBiimlendirilmiChar
        {mso-style-name:"HTML \00D6nceden Bi\00E7imlendirilmi\015F Char";
        mso-style-priority:99;
        mso-style-link:"HTML \00D6nceden Bi\00E7imlendirilmi\015F";
        font-family:"Courier New";}
span.hljs-keyword
        {mso-style-name:hljs-keyword;}
span.hljs-type
        {mso-style-name:hljs-type;}
span.hljs-builtin
        {mso-style-name:hljs-built_in;}
span.hljs-number
        {mso-style-name:hljs-number;}
span.hljs-string
        {mso-style-name:hljs-string;}
span.hljs-literal
        {mso-style-name:hljs-literal;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="TR" link="blue" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">How i can make a textbox only accept alphabetic characters?</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In VB.Net, i do this:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<pre style="vertical-align:baseline"><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Private</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Sub</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> TextBox1_KeyPress(sender </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">As</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> </span></code><span class="hljs-type"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Object</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">, e </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">As</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> KeyPressEventArgs) _</span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Handles</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> txtName.KeyPress<o:p></o:p></span></code></pre>
<pre style="vertical-align:baseline"><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">    </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">If</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> </span></code><span class="hljs-builtin"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Not</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> (Asc(e.KeyChar) = </span></code><span class="hljs-number"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">8</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">) </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Then</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"><o:p></o:p></span></code></pre>
<pre style="vertical-align:baseline"><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">        </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Dim</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> allowedChars </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">As</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> </span></code><span class="hljs-type"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">String</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> = </span></code><span class="hljs-string"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">"abcdefghijklmnopqrstuvwxyz0123456789"</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"><o:p></o:p></span></code></pre>
<pre style="vertical-align:baseline"><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">        </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">If</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> </span></code><span class="hljs-builtin"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Not</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> allowedChars.Contains(e.KeyChar.ToString.ToLower) </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Then</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"><o:p></o:p></span></code></pre>
<pre style="vertical-align:baseline"><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">            e.KeyChar = ChrW(</span></code><span class="hljs-number"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">0</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">)<o:p></o:p></span></code></pre>
<pre style="vertical-align:baseline"><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">            e.Handled = </span></code><span class="hljs-literal"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">True</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"><o:p></o:p></span></code></pre>
<pre style="vertical-align:baseline"><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">        </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">End</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">If</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"><o:p></o:p></span></code></pre>
<pre style="vertical-align:baseline"><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">    </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">End</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">If</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"><o:p></o:p></span></code></pre>
<pre style="vertical-align:baseline"><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"><o:p> </o:p></span></code></pre>
<pre style="vertical-align:baseline"><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">End</span></span><code><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm"> </span></code><span class="hljs-keyword"><span style="font-family:"inherit",serif;border:none windowtext 1.0pt;padding:0cm">Su</span></span><span style="font-family:Consolas"><o:p></o:p></span></pre>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>