mohasad

hi all ,
i am having a doubt in assigning some keys or character values to keycode . My application contains a button , when i press the button it should print '1' or some numbers , in the same way i am having buttons for all the numbers . how to accomplish this .

thanks
sadiq




Re: Visual C# General Assigning values to Keycode

Peter Ritchie

I'm missing the relationship between keys/keycode and pressing a button & printing numbers Do you want a shortcut to your button so that when you press a key the button's Click event is raised What do you mean by "print" Print to printer, Debug.WriteLine, Console,WriteLine, Trace.WriteLine, etc...






Re: Visual C# General Assigning values to Keycode

mohasad

hi ritchie ,
my case is , when i press a button , it should print the value in the textbox as '1' . that is i am having a buttons from 0-9 , when i press button it should give the corresponding number value in textbox . i hope now you get a clear idea about my problem.
thanks
sadiq





Re: Visual C# General Assigning values to Keycode

Peter Ritchie

You still haven't clarified what that has to do with keycodes or keys; but:

void Button1_Click(object sender, EventArgs e)

{

textBox1.Text += "1";

}






Re: Visual C# General Assigning values to Keycode

mohasad

hi ,
what i mean by keycode is when i press the button e.g '1' , it should give the keycode as '1' . how to achieve this .. that is when the button is pressed it should give the keycode for '1'.

thanks
sadiq





Re: Visual C# General Assigning values to Keycode

Figo Fei - MSFT

Hi, mohasad

What did you mean "keycode"

What exactly you want to achieve

Thanks






Re: Visual C# General Assigning values to Keycode

Matthew Watson

@mohasad:

Did you want the textbox to show the same text as the button when the user clicks the button

If so, attach ALL your buttons to this button click handler (no need for a different handler for each button):



private void button_Click(object sender, EventArgs e)
{
Button button = sender as Button;

if (button != null)
textBox1.Text = button.Text;
}







Re: Visual C# General Assigning values to Keycode

mohasad

hi Figo ,
the thing that i want to achieve is when i press a button i.e . named '1' , it should give the output like as if i have pressed the number key '1'. because i want to make some processing with that keycode . Is there any way to process .

thanks
sadiq





Re: Visual C# General Assigning values to Keycode

Matthew Watson

Ahhh, you need to look at the SendKeys class.




Re: Visual C# General Assigning values to Keycode

Figo Fei - MSFT

Yes, just as Matthew said, for more information, see: http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.send(VS.80).aspx

Thanks