[英]Sending values to text box during run time
I am running a console application. 我正在运行控制台应用程序。 I am having a textbox in a form.
我在表单中有一个文本框。 I need to calculate number of messages read in last five minutes in another class and display the value in textbox.
我需要计算最近五分钟在另一个类中读取的消息数,并在文本框中显示该值。 When I run the code I can able to see the textbox.text value correctly.
运行代码时,我可以正确看到textbox.text值。 But in UI I can't see the value is displayed in the textbox.
但是在UI中,我看不到该值显示在文本框中。 But I can able to edit the textbox manually during runtime.
但是我可以在运行时手动编辑文本框。
Here is my code: 这是我的代码:
In codebehind 在代码背后
for (int i = 1; i <= numberOfMsgs; i++)
{
if (addDateTime.AddMinutes(2).Minute==DateTime.Now.Minute)
{
//FilesProcessedInFiveMinutes();
//Thread thread1 = new Thread(new ThreadStart(FiveMinutesMessage));
//thread1.Start();
WebSphereUI webSphereUi = new WebSphereUI();
webSphereUi.count(fiveMinutesCount);
addDateTime = DateTime.Now;
}
fiveMinutesCount = fiveMinutesCount + 1;
}
In form.cs 在form.cs中
public void count(int countValue)
{
Thread.Sleep(2000);
txtLastFiveMins.Focus();
txtLastFiveMins.Text = countValue.ToString();
txtLastFiveMins.Refresh();
txtLastFiveMins.Show();
backgroundWorker1.RunWorkerAsync(2000);
}
It looks like you are creating a new form every time you enter the if statement. 好像您每次输入if语句都在创建一个新表单。 This line is creating a new
WebSphereUI
form: 此行正在创建新的
WebSphereUI
表单:
WebSphereUI webSphereUi = new WebSphereUI();
Then, you call the count
method on it: 然后,在其上调用
count
方法:
webSphereUi.count(fiveMinutesCount);
But then you you continue on, without showing this form. 但是随后您继续操作,而未显示此表单。 If you add:
如果添加:
webSphereUi.Show();
Then you might see the form appear on the screen, displaying the value as expected. 然后,您可能会看到表单出现在屏幕上,并按预期显示值。 However, this is going to show a new form every time the if statement is executed.
但是,这将在每次执行if语句时显示一种新形式。 You could reuse the same form by declaring it elsewhere, and using it in the loop:
您可以通过在其他地方声明相同的形式并在循环中使用它来重用相同的形式:
class yourClass
{
WebSphereUI webSphereUi = new WebSphereUI();
...
private void yourFunction()
{
for (int i = 1; i <= numberOfMsgs; i++)
{
if (addDateTime.AddMinutes(2).Minute==DateTime.Now.Minute)
{
webSphereUi.count(fiveMinutesCount);
webSphereUi.Show();
addDateTime = DateTime.Now;
}
fiveMinutesCount = fiveMinutesCount + 1;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.