예제 #1
0
        // sort and reflow controls
        public void UpdateFriends()
        {
            List <Friend> friendsList = GetFriends();

            friendsList.Sort(compareFriends);

            int scroll = friendsFlow.VerticalScroll.Value;

            friendsFlow.SuspendLayout();

            int clientIndex = 0;

            foreach (Friend friend in friendsList)
            {
                FriendControl friendControl = null;

                foreach (FriendControl fc in friendsFlow.Controls)
                {
                    if (fc.Friend.Equals(friend))
                    {
                        friendControl = fc;
                        break;
                    }
                }

                if (friendControl == null)
                {
                    friendControl = new FriendControl(friend);
                    friendsFlow.Controls.Add(friendControl);
                }
                else
                {
                    friendControl.UpdateFriend(friend);
                }

                friendsFlow.Controls.SetChildIndex(friendControl, clientIndex);
                clientIndex++;
            }

            List <FriendControl> controlsToRemove = new List <FriendControl>();

            foreach (FriendControl fc in friendsFlow.Controls)
            {
                if (!friendsList.Contains(fc.Friend))
                {
                    controlsToRemove.Add(fc);
                }
            }

            controlsToRemove.ForEach(fc => friendsFlow.Controls.Remove(fc));

            ResizeFriends();

            friendsFlow.ResumeLayout();
            friendsFlow.PerformLayout();
            friendsFlow.Refresh();

            friendsFlow.VerticalScroll.Value = scroll;
        }
예제 #2
0
        // sort and reflow controls
        public void UpdateFriends()
        {
            List<Friend> friendsList = GetFriends();
            friendsList.Sort( compareFriends );

            int scroll = friendsFlow.VerticalScroll.Value;

            friendsFlow.SuspendLayout();

            int clientIndex = 0;

            foreach ( Friend friend in friendsList )
            {
                FriendControl friendControl = null;
                
                foreach( FriendControl fc in friendsFlow.Controls )
                {
                    if ( fc.Friend.Equals( friend ) )
                    {
                        friendControl = fc;
                        break;
                    }
                }

                if ( friendControl == null )
                {
                    friendControl = new FriendControl( friend );
                    friendsFlow.Controls.Add( friendControl );
                }
                else
                {
                    friendControl.UpdateFriend( friend );
                }

                friendsFlow.Controls.SetChildIndex( friendControl, clientIndex );
                clientIndex++;
            }

            List<FriendControl> controlsToRemove = new List<FriendControl>();
            foreach (FriendControl fc in friendsFlow.Controls)
            {
                if (!friendsList.Contains(fc.Friend))
                {
                    controlsToRemove.Add(fc);
                }
            }

            controlsToRemove.ForEach( fc => friendsFlow.Controls.Remove( fc ) );

            ResizeFriends();

            friendsFlow.ResumeLayout();
            friendsFlow.PerformLayout();
            friendsFlow.Refresh();

            friendsFlow.VerticalScroll.Value = scroll;
        }