[英]Wait until user press enter in textbox in another form and return value
我是C#的新手,我正在嘗試執行以下操作:
myList = list of 1000+ string values;
1.StartNewThreads(50); //50 is the numbers of new threads
2.DoSth1(next value from myList);
3.DoSth2();
4. var value = {
ShowNewImageForm(); //show only if not another ImageForm is displayed if another is show - wait
WaitUntilUserPressEnterInTextBox();
ReturnValueFormTextbox();
}
5.DoSth3();
6.StartNewThread();
現在,我有:
foreach(String s in myList ) {
DoSth1(s);
DoSth2();
DoSth3();
}
現在我正在尋找指向1,3,6點的想法,您能建議我如何解決這個問題嗎?
對於第二個問題:只需在子表單的構造函數中傳遞父表單/所有者表單,然后使用該引用來傳遞/設置返回值,或者(更優雅)定義一個事件,一旦用戶按下return就會在子表單上觸發鍵,然后在您的父表單中添加事件處理程序。
要啟動一些線程,可以使用Thread []
public static void StartThreads(int n)
{
System.Threading.Thread[] threads = new System.Threading.Thread[n];
for (int i = 0; i < threads.Length; i++)
{
threads[i] = new System.Threading.Thread(new System.Threading.ThreadStart(DoThread));
}
}
public static void DoThread()
{
//do some here
}
在第二種形式中,您可以定義此處理程序:
public static void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
TextBox myText = (TextBox)sender;
//your code here...
}
}
然后以第一種形式:
textBox1.KeyDown += new KeyEventHandler(Form2.textBox1_KeyDown);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.