Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. how to programatically raise keyPress event of a user control?

how to programatically raise keyPress event of a user control?

Scheduled Pinned Locked Moved Windows Forms
csharpwinformstutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imak
    wrote on last edited by
    #1

    I have a user control that contains a textbox control. I am getting some data from serial port. Anytime i get this data I need to raise keypress event of the user control that should internally riase keypress event of text box. I am a newbie to winforms and will very much appreciate if someone can walk me through steps on how to do this.

    L 1 Reply Last reply
    0
    • I imak

      I have a user control that contains a textbox control. I am getting some data from serial port. Anytime i get this data I need to raise keypress event of the user control that should internally riase keypress event of text box. I am a newbie to winforms and will very much appreciate if someone can walk me through steps on how to do this.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, two comments: 1. are you sure you want KeyPress events? if all you want is append some text to a TextBox, why not use the TextBox.AppendText() method? 2. if you use SerialPort.DataReceived event, you must be aware that event does not fire on the main/GUI thread; hence you cannot directly touch GUI Controls, you will need Control.InvokeRequired and Control.Invoke. If those are unfamiliar, search for InvokeRequired. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      I 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, two comments: 1. are you sure you want KeyPress events? if all you want is append some text to a TextBox, why not use the TextBox.AppendText() method? 2. if you use SerialPort.DataReceived event, you must be aware that event does not fire on the main/GUI thread; hence you cannot directly touch GUI Controls, you will need Control.InvokeRequired and Control.Invoke. If those are unfamiliar, search for InvokeRequired. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        I Offline
        I Offline
        imak
        wrote on last edited by
        #3

        Thanks for your response. My real problem is much more complicated so I am just used a simple example. All I basically need is to know how can I programatically raise keypress event of a text box that is contained within a user control. Any code example will be highly appreciated

        I 1 Reply Last reply
        0
        • I imak

          Thanks for your response. My real problem is much more complicated so I am just used a simple example. All I basically need is to know how can I programatically raise keypress event of a text box that is contained within a user control. Any code example will be highly appreciated

          I Offline
          I Offline
          imak
          wrote on last edited by
          #4

          Any ideas about this guys? I really need it very urgently. TIA

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups