解决方案 »
- 【版务帖】2009年2月C#版务帖
- C#如何连接远程的sql server 2000数据库
- 点击两个按钮执行同样的操作 ,怎么知道点击的是哪一个?
- 快捷键设置不成功,高手帮忙看一下是怎么回事啊(c#,winform)
- 求助:我怎么实现在sql server里 写log?并且能方便查询,用c#做报表?
- groupbox触发事件
- 急问:新建解决方案出问题了!!!
- 怪!怪!怪!listView1.Scrollable = true为什么仍然没有滚动条
- C#怎样读取XML文件到TEXT
- c#中如何使用Treeview
- comboBox如何绑定数据源
- c# dataGridView 分页后如何保证每一页的行号连续
this.listView1.Items[ff].SubItems[0].Text,那我问你,这个控件你用什么赋值的,我分析2种可能。1,this.listView1.Items[ff].SubItems[0].Text是你画面的值,那简单,线程构造的时候是可以带参数的,具体怎么做,自己想,肯定可以2,this.listView1.Items[ff].SubItems[0].Text是先通过数据库附好的,那我真OOXX了 ,你不 会用数据库的变量直接赋值啊PS:上下文不清楚,我觉得主要问题是你不知道带参数传进去。
一句话,需要什么,都传进去不就好了(传个list解决所有问题)其实,while(ff<total) ->改成for each (list),不能说了,再不行,我无语
/// <summary>
/// 定义委托
/// </summary>
/// <param name="m_t">文件大小</param>
/// <param name="m_p">当前位置</param>
public delegate void SendFileHandler(int m_t, int m_p);
/// <summary>
/// 定义事件,这个事件将被主线程捕捉,并对主线程 进度条进行修改。
/// </summary>
public event SendFileHandler m_SpFlHandler; public void SendFile()
{
m_SpFlHandler += new SendFileHandler(ChgProgress); Thread t = new Thread(StartSend);
t.Start(); }
//开始发送文件
public void StartSend()
{
//连接到好友客服端
p2pClient= this.GetP2PClient();
ns=p2pClient.GetStream(); FileStream fs = new FileStream(fullName, FileMode.Open, FileAccess.Read);
this.progressBar1.Visible = true;
this.label10.Visible = true;
int m_totalSize = 0;
int m_curPosition = 0; //源文件大小
m_totalSize = (int)fs.Length; byte[] bys = new byte[length];
while (true)
{
int read=fs.Read(bys, 0, bys.Length);
if (read <= 0)
{
break;
} ns.Write(bys, 0, bys.Length);
ns.Flush(); m_curPosition += read;
this.label10.Text = string.Format("{0}%", (int)(m_curPosition*100/m_totalSize));
//触发事件
m_SpFlHandler(m_totalSize, m_curPosition); Thread.Sleep(50);
}
this.progressBar1.Visible = false;
this.richTextBox2.Text += string.Format("文件:{0} 发送成功,(总大小:{1}KB)\r\n", fileName, (int)length / 1024); this.richTextBox2.SelectionStart = this.richTextBox2.Text.Length;
this.richTextBox2.ScrollToCaret();
} //改变进度条的值
private void ChgProgress(int m_t, int m_p)
{
progressBar1.Maximum = m_t;
progressBar1.Value = m_p;
}
public delegate string delegateGetCotrolValue(int nItemIndex);
2.定义取控件的方法
private string GetUserNameValue(int nItemIndex)
{
return this.listView1.Items[nItemIndex].SubItems[0].Text.Split('\\')[0];
} private string GetFileNameValue(int nItemIndex)
{
return this.listView1.Items[nItemIndex].SubItems[0].Text.Split('\\')[1]; }3.调用 UserName = (string)this.Invoke(new delegateGetCotrolValue(GetUserNameValue), new object[] { ff});
FileName = (string)this.Invoke(new delegateGetCotrolValue(GetFileNameValue), new object[] { ff });