weird keypress problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lasse Edsvik

    #1

    weird keypress problem

    Hello

    I have this code in my project and it doesnt work, what might be wrong?

    private void Textbox1_KeyPre ss(object sender,
    System.Windows. Forms.KeyPressE ventArgs e)

    {

    if (e.KeyChar == '\n')

    {

    Textbox2.Text = "KKK";

    Textbox1.Text = "";

    }

    }



    nothing happens :( no errors when compiling either......



    any ideas?

    /Lasse






  • Pronojit Roy

    #2
    Re: weird keypress problem

    Hi Lasse,
    the solve is e.KeyChar == (char)13

    pronojit

    "Lasse Edsvik" <lasse@nospam.c om> wrote in message
    news:uQ3CtWohDH A.2212@tk2msftn gp13.phx.gbl...[color=blue]
    > Hello
    >
    > I have this code in my project and it doesnt work, what might be wrong?
    >
    > private void Textbox1_KeyPre ss(object sender,
    > System.Windows. Forms.KeyPressE ventArgs e)
    >
    > {
    >
    > if (e.KeyChar == '\n')
    >
    > {
    >
    > Textbox2.Text = "KKK";
    >
    > Textbox1.Text = "";
    >
    > }
    >
    > }
    >
    >
    >
    > nothing happens :( no errors when compiling either......
    >
    >
    >
    > any ideas?
    >
    > /Lasse
    >
    >
    >
    >
    >
    >[/color]


    Comment

    • Matt Garven

      #3
      Re: weird keypress problem

      Alternatively, you could try hooking into the KeyDown event...

      private void Textbox1_KeyDow n(object sender, KeyEventArgs e)
      {
      if (e.KeyData == Keys.Enter)
      {
      ...
      }
      }

      If you wish to compare with a char, you can cast the Keys enumeration to a
      Char. Your original issue would have been that you wanted '\r' anyway. For
      readability, I suggest:

      char Enter = (char)Keys.Ente r;

      --
      Regards,
      Matt
      matt_garven@iin et.net.au


      "Pronojit Roy" <pronojitroy@ho tmail.com> wrote in message
      news:eCVEYwohDH A.1172@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Hi Lasse,
      > the solve is e.KeyChar == (char)13
      >
      > pronojit
      >
      > "Lasse Edsvik" <lasse@nospam.c om> wrote in message
      > news:uQ3CtWohDH A.2212@tk2msftn gp13.phx.gbl...[color=green]
      > > Hello
      > >
      > > I have this code in my project and it doesnt work, what might be wrong?
      > >
      > > private void Textbox1_KeyPre ss(object sender,
      > > System.Windows. Forms.KeyPressE ventArgs e)
      > >
      > > {
      > >
      > > if (e.KeyChar == '\n')
      > >
      > > {
      > >
      > > Textbox2.Text = "KKK";
      > >
      > > Textbox1.Text = "";
      > >
      > > }
      > >
      > > }
      > >
      > >
      > >
      > > nothing happens :( no errors when compiling either......
      > >
      > >
      > >
      > > any ideas?
      > >
      > > /Lasse
      > >
      > >
      > >
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...