//刷新好友列表 private void RefreshFriendList() { object target = this.lstOnline.SelectedItem; this.lstOnline.Items.Clear(); this.lstUsers.Items.Clear(); //请求获取好友列表 WebServiceMessage.Friends[] friends = WsMessage.GetFriendList(); WebServiceMessage.WSMessage wsm = new WebServiceMessage.WSMessage(); //遍历添加用户 foreach (var f in friends) { this.lstUsers.Items.Add(f.FriendName);//第一个ListBox显示全部好友 if (wsm.IsOnline(f.FriendName)) { this.lstOnline.Items.Add(f.FriendName);//第二个显示在线好友 } } if (target != null) { if (this.lstOnline.Items.Contains(target)) { this.lstOnline.SelectedItem = target; } } }