Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing calculator program.As like windows calcultor on press its textbox get focused and cause to input. In code it dont get focused on key press.
I need manually click on textbox and then It take input from keyboard.

C#
private void onKeyPress(object sender, KeyPressEventArgs e)
      {
          if (!char.IsControl(e.KeyChar) &&  char.IsDigit(e.KeyChar) &&(e.KeyChar != '.'))
          {
              e.Handled = true;
          }

          // only allow one decimal point
          if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
          {
              e.Handled = true;
          }
         txtResult.text = e.keyChar;
      }

still it dont get focus on keypress.
Posted
Updated 18-Jun-15 21:44pm
v2
Comments
Ralf Meier 17-Jun-15 1:03am    
For my understanding :
You don't press a key inside the TextBox ... you press a Button and after this you want to have the Focus on the TextBox ?

please call a function followed by onkeypress Attribute, Something like this:



or alternately:



function myFunction()
{
textbox1.focus();
}
 
Share this answer
 
if your calculator program in a web page then write java script function.

JavaScript
$(document).ready(function () {
 textbox1.focus();
 });



for window application this link may be useful.

http://stackoverflow.com/questions/6597196/how-to-put-focus-on-textbox-when-the-form-load[^]
 
Share this answer
 
v2
Comments
Sarita S 17-Jun-15 1:12am    
It is windows form application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900