c# - How do i wait until a String returns a value? -


i have program uses keypress event add new character new label, sort of console application. need add input method program when press enter instead of executing function, returns string. have tried making keypress event return string doesn't work obvious reasons, how make work?

note: "return string" mean;

if ask console wait input still using keypress event return string/input user.

i hope understand code have written, note extends other

my keypress event handler:

private void form1_keypress(object sender, keypresseventargs e)     {         if (e.keychar == '\b') // backspace         {             if (ll.text != "_" && actualtext != "") // there characters remove?             {                 actualtext = ll.text.substring(0, actualtext.length - 1);                 ll.text = actualtext + "_";             }          }         else             if (e.keychar == (char)13)             {                 if (!inputmode)                 {                     foreach (keyvaluepair<string, action> cm in base.command())                     {                          if (actualtext == cm.key)                         {                             print(actualtext);                             cm.value();                          }                     }                 }                 else                 {                     inputmode = false;                     lastinput = actualtext;                     print("input >> "+lastinput);                  }                 actualtext = "";                 ll.text = actualtext + "_";             }             else             if (!char.iscontrol(e.keychar)) // ignore control chars such enter.             {                 actualtext = actualtext + e.keychar.tostring();                 ll.text = actualtext + "_";             }     } 

your question bit unclear, if got right, solution instead of return string, can't in keypress event, raise own event, so

public delegate void enterpressedhndlr(string mystring);  public partial class form1 : form {   public event enterpressedhndlr enterpressed;    void form1_keypress(object sender, keypresseventargs e)   {      //your calculation      if (enterpressed != null)      {         enterpressed("your data");      }   } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -