public void UpdateUserLevel(User user, byte before) { if (this.userListBox1.InvokeRequired) { this.userListBox1.BeginInvoke(new UULHandler(this.UpdateUserLevel), user, before); } else { bool section_changing = ((before == 0 && user.Level > 0) || (before > 0 && user.Level == 0)) && !user.IsFriend; int index = -1; UserListBoxSectionType section = UserListBoxSectionType.Friends; for (int i = 0; i < this.userListBox1.Items.Count; i++) { if (this.userListBox1.Items[i] is UserListBoxItem) { if (((UserListBoxItem)this.userListBox1.Items[i]).Owner.Name == user.Name) { index = i; break; } } else if (this.userListBox1.Items[i] is UserListBoxSectionItem) { section = ((UserListBoxSectionItem)this.userListBox1.Items[i]).Section; } } if (index > -1) { UserListBoxItem item = (UserListBoxItem)this.userListBox1.Items[index]; if (section_changing) { int ti = this.userListBox1.TopIndex; this.userListBox1.Items.RemoveAt(index); this.userListBox1.TopIndex = ti < this.userListBox1.Items.Count ? ti : (this.userListBox1.Items.Count - 1); ti = this.userListBox1.TopIndex; this.CheckSectionEmpty(section); this.userListBox1.TopIndex = ti < this.userListBox1.Items.Count ? ti : (this.userListBox1.Items.Count - 1); this.AddUserItem(user); } else { this.userListBox1.Invalidate(this.userListBox1.GetItemRectangle(index)); } } } }
public void UpdateUserFriendship(User user) { if (this.userListBox1.InvokeRequired) { this.userListBox1.BeginInvoke(new RUIHandler(this.UpdateUserFriendship), user); } else { int index = -1; UserListBoxSectionType section = UserListBoxSectionType.Friends; for (int i = 0; i < this.userListBox1.Items.Count; i++) { if (this.userListBox1.Items[i] is UserListBoxItem) { if (((UserListBoxItem)this.userListBox1.Items[i]).Owner.Name == user.Name) { index = i; break; } } else if (this.userListBox1.Items[i] is UserListBoxSectionItem) { section = ((UserListBoxSectionItem)this.userListBox1.Items[i]).Section; } } if (index > -1) { UserListBoxItem item = (UserListBoxItem)this.userListBox1.Items[index]; int ti = this.userListBox1.TopIndex; this.userListBox1.Items.RemoveAt(index); this.userListBox1.TopIndex = ti < this.userListBox1.Items.Count ? ti : (this.userListBox1.Items.Count - 1); ti = this.userListBox1.TopIndex; this.CheckSectionEmpty(section); this.userListBox1.TopIndex = ti < this.userListBox1.Items.Count ? ti : (this.userListBox1.Items.Count - 1); this.AddUserItem(user); } } }