一个窗体类Form1 一个按钮button 一个ListBox
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsApplication1
{
public partial class Form1 : Form
{
aa AA = new aa();
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(AA.tianjia));
t.Start();
}
}
}一个自建类 aausing System;
using System.Collections.Generic;
using System.Text;namespace WindowsApplication1
{
class aa
{
public void tianjia()
{
for (int i = 0; i < 10; i++)
{
string str=i
}
}
}
}如何在窗体上的ListBox中显示i的值?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsApplication1
{
public partial class Form1 : Form
{
aa AA = new aa();
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(AA.tianjia));
t.Start();
}
}
}一个自建类 aausing System;
using System.Collections.Generic;
using System.Text;namespace WindowsApplication1
{
class aa
{
public void tianjia()
{
for (int i = 0; i < 10; i++)
{
string str=i
}
}
}
}如何在窗体上的ListBox中显示i的值?
解决方案 »
- 数据写入DataGridView的同时写入txtBox里面去?
- 如何做到隐式调用
- WebBrowser如何执行完整的script脚本
- 急求助: Page 指令中将 enableSessionState 设置为 true 时,才能使用会...
- C# 视频解码包?
- [60分] WinForm 中如何支持多语言显示 ? (语言资源另存在 xml 文档中)
- 在linux下怎么用mono GTK# 编写简单的计算器~!!!! 急用
- WEB 里面对话框提示“确定”和“取消”的功能的老问题,高手帮忙看看!
- 如何使DataGrid表中行数据进入编辑模式?
- c#.net winform里form2 怎样能够修改form1中的label控件的text值呀?急用!!!!(在线等)
- Allchina.cn招聘C#.net程序员(北京地区)
- 在datagridview中如何显示某表的部分字段内容?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading; public partial class Form2 : Form
{
public delegate void AddListItem(string s);//声明委托
public AddListItem myDelegate; public Form2()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
myDelegate = new AddListItem(AddtoListBox); aa AA = new aa(this);
Thread th = new Thread(new ThreadStart(AA.tianjia));//开辟新线程
th.Start(); } public void AddtoListBox(string s)
{
listBox1.Items.Add(s);//给列表框添加一项
}
}
public class aa
{
Form2 frm;
public aa(Form2 frm)
{
this.frm = frm;
}
public void tianjia()
{
for (int i = 0; i < 10; i++)
{
frm.Invoke(frm.myDelegate, new Object[] { i.ToString() });//委托调用
}
}
}