本帖最后由 zhucemajiaburongyi 于 2010-01-07 14:05:20 编辑

解决方案 »

  1.   

    我OOXX,都可以赋值了,还不能取值,
    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),不能说了,再不行,我无语
      

  2.   


    /// <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;            
            }
      

  3.   

    1.定义委托
    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 });