C# 显示文本框。Windows窗体中带有“文本”的文本;idx“;遍历for循环
这是我的第一个C#项目。我有两个.cs文件,一个包含所有与GUI相关的内容(Form1.cs),另一个包含我的处理(GMF.cs)。当用户单击GUI上的“开始”(一个C# 显示文本框。Windows窗体中带有“文本”的文本;idx“;遍历for循环,c#,.net,winforms,visual-studio-2010,C#,.net,Winforms,Visual Studio 2010,这是我的第一个C#项目。我有两个.cs文件,一个包含所有与GUI相关的内容(Form1.cs),另一个包含我的处理(GMF.cs)。当用户单击GUI上的“开始”(一个按钮)时,控制传递到Form1.cs,它在内部调用GMF.cs文件中的GMFMat() 在Form1.cs中,我有: private void button1_Click(object sender, EventArgs e) // Start Processing button clicked. { GMF n = new
按钮
)时,控制传递到Form1.cs,它在内部调用GMF.cs文件中的GMFMat()
在Form1.cs中,我有:
private void button1_Click(object sender, EventArgs e) // Start Processing button clicked.
{
GMF n = new GMF();
func_out = n.GMFMat(inputs_GUI, this.progressBar1, this.textBox_imageNumber);
}
private void timer1_Tick(object sender, EventArgs e) // Increment Progress Bar
{
progressBar1.Increment(1);
}
private void textBox_imageNumber_TextChanged(object sender, EventArgs e)
{
this.Text = textBox_imageNumber.Text;
Console.Write("Text = " + textBox_imageNumber.Text);
}
class GMF
{
public Tuple<string, int> GMFMat(in_params input_from_GUI, System.Windows.Forms.ProgressBar bar, System.Windows.Forms.TextBox textBox_ImgNumber)
{
double nth_file = 0;
double num_files = 100
foreach (string dir in dirs) // For our example, say 100 ierations
{
nth_file = nth_file + 1;
textBox_ImgNumber.Text = nth_file.ToString();
// Progress bar updates in each iteration, and I can see it as it progresses on the windows Form during execution.
bar_value_percent = nth_file / num_files * 100;
bar.Value = int.Parse(Math.Truncate(bar_value_percent).ToString());
}
}
}
在GMF.cs中,我有:
private void button1_Click(object sender, EventArgs e) // Start Processing button clicked.
{
GMF n = new GMF();
func_out = n.GMFMat(inputs_GUI, this.progressBar1, this.textBox_imageNumber);
}
private void timer1_Tick(object sender, EventArgs e) // Increment Progress Bar
{
progressBar1.Increment(1);
}
private void textBox_imageNumber_TextChanged(object sender, EventArgs e)
{
this.Text = textBox_imageNumber.Text;
Console.Write("Text = " + textBox_imageNumber.Text);
}
class GMF
{
public Tuple<string, int> GMFMat(in_params input_from_GUI, System.Windows.Forms.ProgressBar bar, System.Windows.Forms.TextBox textBox_ImgNumber)
{
double nth_file = 0;
double num_files = 100
foreach (string dir in dirs) // For our example, say 100 ierations
{
nth_file = nth_file + 1;
textBox_ImgNumber.Text = nth_file.ToString();
// Progress bar updates in each iteration, and I can see it as it progresses on the windows Form during execution.
bar_value_percent = nth_file / num_files * 100;
bar.Value = int.Parse(Math.Truncate(bar_value_percent).ToString());
}
}
}
类转基因食品
{
公共元组GMFMat(从GUI、System.Windows.Forms.ProgressBar栏、System.Windows.Forms.TextBox TextBox\u imgnNumber中输入参数)
{
双N_文件=0;
double num_files=100
foreach(dirs中的string dir)//对于我们的示例,假设为100个ierations
{
第n个文件=第n个文件+1;
textBox_ImgNumber.Text=n_file.ToString();
//进度条在每次迭代中都会更新,我可以在执行期间在windows窗体上看到进度条的进展。
bar\u value\u percent=n个文件/num\u文件*100;
bar.Value=int.Parse(Math.Truncate(bar\u Value\u percent.ToString());
}
}
}
cs[Design]有一个文本框(我简单地从工具箱中拖拽)。我重命名了(名称)=文本框\u图像编号
- 该值每次进入for循环时递增1李>
- 这样做的基本目的是,每当for循环完成1000次迭代时,我希望用户知道(在表单应用程序上显示一条消息)李>
Text=1,Text=2。。。Text=100
随着程序的进行。-这表明textBox_ImgNumber.Text中变量的值正在GMF.cs的for循环中更新,并达到Form1.csfunc\u out=n.GMFMat(输入\u GUI、this.progressBar1、this.textBox\u imageNumber)中出来代码>,文本框的值显示为100
Application.DoEvents()代码>
因此,在Form1.cs中:
private void textBox_imageNumber_TextChanged(object sender, EventArgs e)
{
this.Text = textBox_imageNumber.Text;
Console.Write("Text = " + textBox_imageNumber.Text);
Application.DoEvents();
}
GMF n=新的GMF()代码>此表单从未显示,因此用户从未与之交互。是否尝试?谢谢您的评论。我可能会更新我的问题,以解决上述问题。