Esempio n. 1
0
        /// <summary>
        /// 用于获取歌曲列表,并更新
        /// </summary>
        /// <param name="listViewItems"></param>
        private void UpdateUI(List <ListViewItem> listViewItems)
        {
            if (this.lvSongs.InvokeRequired)// 如果调用控件的线程和创建创建控件的线程不是同一个则为True
            {
                while (!this.lvSongs.IsHandleCreated)
                {
                    if (this.lvSongs.Disposing || this.lvSongs.IsDisposed)
                    {
                        return;
                    }
                    UpdateListCallback d = new UpdateListCallback(UpdateUI);
                    lvSongs.Invoke(d, new object[] { listViewItems });
                }
            }
            else
            {
                lvSongs.BeginUpdate(); //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可有效避免闪烁大大提高加载速度
                lvSongs.Items.AddRange(listViewItems.ToArray());
                lvSongs.EndUpdate();   //结束数据处理,UI界面一次性绘制
                tsLable.Text = "搜索完成";
                StopProcessBar();

                if (lvSongs.Items.Count > 0)
                {
                    btnNextPage.Enabled = true;
                }
                else
                {
                    btnNextPage.Enabled = false;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 用于在获取歌曲列表的Task中更新界面
        /// </summary>
        /// <param name="listViewItems"></param>
        private void UpdateUI(List <ListViewItem> listViewItems)
        {
            if (this.listViewResult.InvokeRequired)//如果调用控件的线程和创建创建控件的线程不是同一个则为True
            {
                while (!this.listViewResult.IsHandleCreated)
                {
                    //解决窗体关闭时出现“访问已释放句柄“的异常
                    if (this.listViewResult.Disposing || this.listViewResult.IsDisposed)
                    {
                        return;
                    }
                }
                UpdateListCallback d = new UpdateListCallback(UpdateUI);
                listViewResult.Invoke(d, new object[] { listViewItems });
            }
            else
            {
                listViewResult.BeginUpdate(); //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
                listViewResult.Items.AddRange(listViewItems.ToArray());
                listViewResult.EndUpdate();   //结束数据处理,UI界面一次性绘制
                toolStripStatusLabel1.Text = "搜索完成";
                StopProcessBar();

                if (listViewResult.Items.Count > 0)
                {
                    btnNextPage.Enabled = true;
                }
                else
                {
                    btnNextPage.Enabled = false;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 用于在获取歌曲列表的Task中更新界面
 /// </summary>
 /// <param name="listViewItems"></param>
 private void UpdateUI(List <ListViewItem> listViewItems)
 {
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (this.resultListView.InvokeRequired)//如果调用控件的线程和创建创建控件的线程不是同一个则为True
     {
         while (!this.resultListView.IsHandleCreated)
         {
             //解决窗体关闭时出现“访问已释放句柄“的异常
             if (this.resultListView.Disposing || this.resultListView.IsDisposed)
             {
                 return;
             }
         }
         UpdateListCallback d = new UpdateListCallback(UpdateUI);
         resultListView.Invoke(d, new object[] { listViewItems });
     }
     else
     {
         resultListView.BeginUpdate(); //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
         resultListView.Items.AddRange(listViewItems.ToArray());
         resultListView.EndUpdate();   //结束数据处理,UI界面一次性绘制
         toolStripStatusLabel1.Text = "搜索完成";
         StopProcessBar();
     }
 }
Esempio n. 4
0
        private void UpdateList()
        {
            ///<summary>
            /// Update the content of the form listing all the known users with the relative images.
            /// At the end of the method, the form is shown.
            ///</summary>

            if (this.InvokeRequired)
            {
                /* The current thread is not the owner of the form so the owner
                 * is asked to call the method to perform the modification
                 */
                UpdateListCallback callback = new UpdateListCallback(UpdateList);
                UserListView.Invoke(callback);
            }
            else
            {
                ImageList imgl = new ImageList();
                Image     img;
                imgl.ImageSize  = new Size(150, 150);                           // The size of the pictures of the user.
                imgl.ColorDepth = ColorDepth.Depth32Bit;                        // The quality of the images. 32bit is the maximum.
                UserListView.Clear();                                           // Clear out the current list of user. It may contains users that are now disconnected.
                lock (Program.users) {
                    #region AddImages
                    foreach (User u in Program.users.Values)
                    {
                        img = Image.FromFile(u.imagePath ?? Program.defaultImagePath);
                        imgl.Images.Add(u.ip, img);
                    }
                    UserListView.LargeImageList = imgl;
                    #endregion
                    #region Add names

                    /* Each image in the image list has an index. Since the list of user is scanned
                     * in the same order, each i-th name in the for will correspond the the i-th image
                     * scanned before, so to get the right index of the current name and image is
                     * enough to use a counter (the local variable "i")
                     */
                    var i = 0;
                    foreach (User u in Program.users.Values)
                    {
                        UserListView.Items.Add(u.ip, u.publicName, i++);

                        /* The image key can be retrived when the item is selected.
                         * By storing the ip of the corresponding user, it will be possible to get all
                         * the information regarding him since the user are stored in a dictionary
                         * where the key is the ip address.
                         */
                        UserListView.Items[i - 1].ImageKey = u.ip;
                    }
                    #endregion
                }
            }
            /* The confirm button has to be enabled only if at least one item is selected */
            Confirm.Enabled = false;
        }
Esempio n. 5
0
		private void UpdateList()
		{
			if (this.InvokeRequired)
			{
				UpdateListCallback updateListCallback = new UpdateListCallback(UpdateList);
				this.Invoke(updateListCallback);
			}
			else
			{
				online_LB.Items.Clear();
				foreach (string str in users.Keys)
				{
					online_LB.Items.Add(str);
				}
			}
		}
Esempio n. 6
0
 public void UpdateList()
 {
     if (m_lvUsers.InvokeRequired)
     {
         UpdateListCallback d = new UpdateListCallback(UpdateList);
         m_lvUsers.Invoke(d);
     }
     else
     {
         foreach (Peer item in Peers)
         {
             ListViewItem test = m_lvUsers.FindItemWithText(item.CallSign);
             if (test == null)
             {
                 int Status = 0;
                 if (item.Disabled)
                 {
                     Status = 4;
                 }
                 ListViewItem P = new ListViewItem(item.CallSign, Status);
                 P.SubItems.Add(new ListViewItem.ListViewSubItem(P, ""));
                 m_lvUsers.Items.Add(P);
                 m_lvUsers.Update();
             }
         }
         for (int i = m_lvUsers.Items.Count - 1; i >= 0; i--)
         {
             Peer test = Peers.Find(x => x.CallSign == m_lvUsers.Items[i].Text);
             if (test == null)
             {
                 m_lvUsers.Items.RemoveAt(i);
                 m_lvUsers.Update();
             }
         }
     }
 }