Example #1
0
 // 触发ProxyEvent事件
 protected void OnProxyEvent(ProxyEventArgs e)
 {
     if (ProxyEvent != null)
     {
         ProxyEvent(this, e);
     }
 }
Example #2
0
 // 如果在线者列表不为空,则触发ProxyEvent事件
 private void HandleEndJoin(Person[] list)
 {
     if (list == null)
     {
         MessageBox.Show("Error: List is empty", "Error",
         MessageBoxButtons.OK, MessageBoxIcon.Error);
         ExitChatSession();
     }
     else
     {
         ProxyEventArgs e = new ProxyEventArgs();
         e.list = list;
         OnProxyEvent(e);
     }
 }
Example #3
0
 //该方法作为ProxyEvent事件绑定的委托所引用的方法
 //通过ProxyEventArgs参数获得所有参与聊天的用户的信息并显示他们的名称
 private void ProxySingleton_ProxyEvent(object sender, ProxyEventArgs e)
 {
     //如果Windows 窗体中的控件被绑定到特定的线程,则不具备线程安全性。
     //因此,如果从另一个线程调用控件的方法,
     //那么必须使用控件的一个 Invoke 方法来将调用封送到适当的线程。
     //InvokeRequired属性可用于确定是否必须调用 Invoke 方法。
     if (this.InvokeRequired)
     {
         this.Invoke(new
         ProxySingleton_ProxyEvent_Delegate(ProxySingleton_ProxyEvent),
         sender, e);
         return;
     }
     lstChatters.View = View.LargeIcon;
     ImageList imageListLarge = new ImageList();
     ImageList imageListSmall = new ImageList();
     imageListSmall.ImageSize = new Size(20, 20);
     imageListLarge.ImageSize = new Size(40, 40);
     int i = 0;
     foreach (Person person in e.list)
     {
         ListViewItem item1 = new ListViewItem(person.Name, i++);
         //利用Tag属性来保存聊天者对象
         item1.Tag = person as object;
         lstChatters.Items.AddRange(new ListViewItem[] { item1 });
         //向ImageList中添加相应图像
         imageListSmall.Images.Add(Bitmap.FromFile(person.ImageURL));
         imageListLarge.Images.Add(Bitmap.FromFile(person.ImageURL));
     }
     lstChatters.SmallImageList = imageListSmall;
     lstChatters.LargeImageList = imageListLarge;
 }