Exemplo n.º 1
0
 private void wnd_MouseLeave(object sender, MouseEventArgs e)
 {
     if (Minimum)
     {
         SlideFade.CreateAnimationToMinimum_min();
     }
 }
Exemplo n.º 2
0
        private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (this.IsMouseOver)
            {
                if (!contact.Pending)
                {
                    if (MainWindow.Instance.page_Chat.ChattingWith != contact || MainWindow.Instance.CurrentPage != "chat")
                    {
                        MainWindow.Instance.btn_home.BorderThickness     = new Thickness(0);
                        MainWindow.Instance.btn_contacts.BorderThickness = new Thickness(0);
                        MainWindow.Instance.btn_chat.BorderThickness     = new Thickness(0, 0, 0, 2);
                        MainWindow.Instance.btn_settings.BorderThickness = new Thickness(0);

                        SlideFade.StartAnimationIn(MainWindow.Instance.page_Chat);

                        MainWindow.Instance.page_Home.Visibility     = System.Windows.Visibility.Hidden;
                        MainWindow.Instance.page_Contacts.Visibility = System.Windows.Visibility.Hidden;
                        MainWindow.Instance.page_Chat.Visibility     = System.Windows.Visibility.Visible;
                        MainWindow.Instance.page_Settings.Visibility = System.Windows.Visibility.Hidden;
                    }

                    MainWindow.Instance.page_Chat.StartChattingWith(contact);
                    if (!App.Instance.OpenChats.Contains(contact))
                    {
                        App.Instance.OpenChats.Add(contact);
                    }
                    contact.MarkAllMessagesRead();

                    MainWindow.Instance.CurrentPage = "chat";
                }
            }
        }
Exemplo n.º 3
0
 private void wnd_StateChanged(object sender, EventArgs e)
 {
     if (wnd.WindowState == System.Windows.WindowState.Normal)
     {
         SlideFade.StartAnimationIn(wnd);
     }
 }
Exemplo n.º 4
0
        void HandleFriendListResponse(ClientSocket clientSocket, Packet pak)
        {
            int FriendsCount = pak.Readint();

            FriendCount = FriendsCount;

            for (int i = 0; i < FriendsCount; i++)
            {
                int FriendID = pak.Readint();
                try
                {
                    clientSocket.SendPacket(Packet.New(Packets.PAK_CLI_MEMINFORQST, FriendID));
                }
                catch (Exception ex) { Console.WriteLine(ex.ToString()); }
            }

            this.Dispatcher.Invoke((MethodInvoker) delegate
            {
                LoginComplete = true;
                BlazeGames.IM.Client.MainWindow.Instance.txt_nickname.Visibility  = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.txt_status.Visibility    = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.txt_search.Visibility    = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.profile_image.Visibility = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.nav_bar.Visibility       = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.listbox1.Visibility      = Visibility.Visible;

                BlazeGames.IM.Client.MainWindow.Instance.btn_ProfileSettings.Visibility = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.btn_AddFriend.Visibility       = Visibility.Visible;

                BlazeGames.IM.Client.MainWindow.Instance.btn_chat.Visibility     = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.btn_close.Visibility    = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.btn_contacts.Visibility = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.btn_home.Visibility     = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.btn_minimize.Visibility = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.btn_settings.Visibility = Visibility.Visible;
                SlideFade.StartAnimationIn(BlazeGames.IM.Client.MainWindow.Instance.wnd);

                BlazeGames.IM.Client.MainWindow.Instance.page_Login.Visibility = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.page_Home.Visibility  = System.Windows.Visibility.Visible;
                SlideFade.StartAnimationIn(BlazeGames.IM.Client.MainWindow.Instance.page_Home);

                BlazeGames.IM.Client.MainWindow.Instance.page_Login.btn_login.Visibility = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.page_Login.Loading.Visibility   = Visibility.Hidden;

                BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_loading.Visibility  = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_account.Visibility  = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_password.Visibility = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_loading.Content     = "Loading Your Account";
            }, null);
        }
Exemplo n.º 5
0
        private void btn_chat_Click(object sender, RoutedEventArgs e)
        {
            if (!App.Instance.LoginComplete || CurrentPage == "chat")
            {
                return;
            }

            if (page_Chat.ChattingWith != null)
            {
                btn_home.BorderThickness     = new Thickness(0);
                btn_contacts.BorderThickness = new Thickness(0);
                btn_chat.BorderThickness     = new Thickness(0, 0, 0, 2);
                btn_settings.BorderThickness = new Thickness(0);

                SlideFade.StartAnimationIn(page_Chat);

                page_Home.Visibility     = System.Windows.Visibility.Hidden;
                page_Contacts.Visibility = System.Windows.Visibility.Hidden;
                page_Chat.Visibility     = System.Windows.Visibility.Visible;
                page_Settings.Visibility = System.Windows.Visibility.Hidden;

                CurrentPage = "chat";
            }
            else
            {
                if (CurrentPage == "contacts")
                {
                    return;
                }

                btn_home.BorderThickness     = new Thickness(0);
                btn_contacts.BorderThickness = new Thickness(0, 0, 0, 2);
                btn_chat.BorderThickness     = new Thickness(0);
                btn_settings.BorderThickness = new Thickness(0);


                SlideFade.StartAnimationIn(page_Contacts);

                page_Home.Visibility     = System.Windows.Visibility.Hidden;
                page_Contacts.Visibility = System.Windows.Visibility.Visible;
                page_Chat.Visibility     = System.Windows.Visibility.Hidden;
                page_Settings.Visibility = System.Windows.Visibility.Hidden;

                CurrentPage = "contacts";
            }
        }
Exemplo n.º 6
0
        private void MenuItem_Click_2(object sender, RoutedEventArgs e)
        {
            if (Minimum)
            {
                SlideFade.CreateAnimationToMaximum();
                Minimum = false;

                App.Instance.OpenChats.Clear();
                view.Refresh();
                SlideFade.CreateAnimationInMinimum(listbox1);
                App.Instance.OpenChats.AddRange(TmpOpenChats);
                view.Refresh();

                Topmost = false;

                btn_maximum1.Visibility = System.Windows.Visibility.Collapsed;
                btn_maximum2.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
Exemplo n.º 7
0
        public void CSocket_ClientSocketDisconnected_Event(object sender, EventArgs e)
        {
            App.Instance.Dispatcher.Invoke((MethodInvoker) delegate
            {
                BlazeGames.IM.Client.MainWindow.Instance.txt_nickname.Visibility  = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.txt_status.Visibility    = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.profile_image.Visibility = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.nav_bar.Visibility       = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.listbox1.Visibility      = Visibility.Hidden;

                BlazeGames.IM.Client.MainWindow.Instance.btn_ProfileSettings.Visibility = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.btn_AddFriend.Visibility       = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.AddFriendWindow.Visibility     = Visibility.Collapsed;

                BlazeGames.IM.Client.MainWindow.Instance.btn_chat.Visibility     = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.btn_close.Visibility    = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.btn_contacts.Visibility = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.btn_home.Visibility     = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.btn_minimize.Visibility = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.btn_settings.Visibility = Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.txt_search.Visibility   = Visibility.Hidden;

                BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_account.Text      = "";
                BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_password.Password = "";
                App.Instance.OpenChats.Clear();
                BlazeGames.IM.Client.MainWindow.Instance.view.Refresh();

                App.Account  = "";
                App.Password = "";
                App.NickName = "";
                App.FullName = "";
                App.Instance.Contacts.Clear();

                BlazeGames.IM.Client.MainWindow.Instance.page_Login.Visibility    = Visibility.Visible;
                BlazeGames.IM.Client.MainWindow.Instance.page_Home.Visibility     = System.Windows.Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.page_Chat.Visibility     = System.Windows.Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.page_Contacts.Visibility = System.Windows.Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.page_Settings.Visibility = System.Windows.Visibility.Hidden;
                BlazeGames.IM.Client.MainWindow.Instance.CurrentPage = "login";
                SlideFade.StartAnimationIn(BlazeGames.IM.Client.MainWindow.Instance.page_Login);
            }, null);
        }
Exemplo n.º 8
0
        private void txt_search_GotFocus(object sender, RoutedEventArgs e)
        {
            if (!App.Instance.LoginComplete)
            {
                return;
            }

            btn_home.BorderThickness     = new Thickness(0);
            btn_contacts.BorderThickness = new Thickness(0, 0, 0, 2);
            btn_chat.BorderThickness     = new Thickness(0);
            btn_settings.BorderThickness = new Thickness(0);


            SlideFade.StartAnimationIn(page_Contacts);

            page_Home.Visibility     = System.Windows.Visibility.Hidden;
            page_Contacts.Visibility = System.Windows.Visibility.Visible;
            page_Chat.Visibility     = System.Windows.Visibility.Hidden;
            page_Settings.Visibility = System.Windows.Visibility.Hidden;

            CurrentPage = "contacts";
        }
Exemplo n.º 9
0
        private void btn_minimize_Click(object sender, RoutedEventArgs e)
        {
            if (!Desktop)
            {
                TmpOpenChats = App.Instance.OpenChats.ToArray();
                App.Instance.OpenChats.Clear();
                view.Refresh();
                SlideFade.CreateAnimationInMinimum(listbox1);
                App.Instance.OpenChats.AddRange(App.Instance.Contacts.Values.ToArray());
                view.Refresh();

                Topmost = true;

                /*LastLeft = Left;
                 * Width = 70;
                 * Left = SystemParameters.PrimaryScreenWidth - 70;
                 * Minimum = true;*/
                SlideFade.CreateAnimationToMinimum();
                btn_maximum1.Visibility = System.Windows.Visibility.Visible;
                btn_maximum2.Visibility = System.Windows.Visibility.Visible;
            }
        }
Exemplo n.º 10
0
        public MainWindow()
        {
            InitializeComponent();

            this.SourceInitialized += new EventHandler(MainWindow_SourceInitialized);

            SlideFade.StartAnimationIn(this);

            view = new ListCollectionView(App.Instance.OpenChats);
            view.SortDescriptions.Add(new System.ComponentModel.SortDescription("LastMessage", System.ComponentModel.ListSortDirection.Descending));
            view.SortDescriptions.Add(new System.ComponentModel.SortDescription("NewMessages", System.ComponentModel.ListSortDirection.Descending));
            view.SortDescriptions.Add(new System.ComponentModel.SortDescription("NickName", System.ComponentModel.ListSortDirection.Ascending));
            view.Refresh();

            this.listbox1.ItemsSource = view;
            //listbox1.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("NewMessages", System.ComponentModel.ListSortDirection.Descending));
            //listbox1.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("NickName", System.ComponentModel.ListSortDirection.Ascending));

            dialog                  = new Microsoft.Win32.OpenFileDialog();
            dialog.Filter           = "Image Files|*.png;*.jpg;*.bmp;*.jpeg";
            dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            dialog.FileOk          += new CancelEventHandler(dialog_FileOk);

            try
            {
                int Width  = Convert.ToInt32(ConfigManager.Instance.GetString("WndWidth", this.Width.ToString()));
                int Height = Convert.ToInt32(ConfigManager.Instance.GetString("WndHeight", this.Height.ToString()));

                if (Width >= SystemParameters.WorkArea.Width || Height >= SystemParameters.WorkArea.Height)
                {
                    return;
                }

                this.Width  = Width;
                this.Height = Height;
            }
            catch { }
        }
Exemplo n.º 11
0
 private void profile_image_MouseLeave(object sender, MouseEventArgs e)
 {
     SlideFade.CancelProfileImgAnimation2();
 }
Exemplo n.º 12
0
 private void rtf_output_MouseLeave(object sender, MouseEventArgs e)
 {
     SlideFade.CreateProfileImgAnimationOut(profile_image);
 }
Exemplo n.º 13
0
        public void StartChattingWith(Contact contact)
        {
            if (ChattingWith != null)
            {
                if (ChattingWith.ID == contact.ID)
                {
                    return;
                }
            }

            if (Uploads.Count > 0)
            {
                NotificationWindow.ShowNotification("Upload In Progress", string.Format("Unable to start chatting with {0} since you are currently uploading files.", contact.FullName));
                return;
            }

            new Thread(new ThreadStart(delegate
            {
                this.Dispatcher.Invoke((App.MethodInvoker) delegate
                {
                    rtf_input.IsEnabled = false;
                }, null);

                this.Dispatcher.Invoke((App.MethodInvoker) delegate
                {
                    ChattingWith = contact;

                    LastMessageFrom = "";

                    profile_image_source.ImageSource   = new System.Windows.Media.Imaging.BitmapImage(new Uri(contact.ProfileImage));
                    profile_image.BorderBrush          = (SolidColorBrush) new BrushConverter().ConvertFromString(contact.status.GetColor());
                    txt_chattingwith_nickname.Text     = contact.FullName;
                    txt_chattingwith_statusupdate.Text = contact.StatusUpdate;

                    rtf_output.SelectAll();
                    rtf_output.Selection.Text = "";
                }, null);

                this.Dispatcher.Invoke((App.MethodInvoker) delegate
                {
                    SlideFade.CreateProfileImgAnimationOut(profile_image);
                    App.Instance.Contacts[contact.ID].LastMessage = DateTime.Now;
                }, null);

                var Messages       = contact.Messages;
                int MessagesToLoad = 50;
                if (Messages.Count > MessagesToLoad)
                {
                    Messages.Reverse();
                    Messages.RemoveRange(MessagesToLoad - 1, Messages.Count - MessagesToLoad);
                    Messages.Reverse();
                }

                foreach (Message msg in Messages)
                {
                    if ((msg.SendTime - DateTime.Now).Days > 7)
                    {
                        continue;
                    }

                    this.Dispatcher.Invoke((App.MethodInvoker) delegate
                    {
                        HandleMessage(msg.From, msg.Msg, true);
                    }, null);
                }

                this.Dispatcher.Invoke((App.MethodInvoker) delegate
                {
                    rtf_input.IsEnabled = true;
                    rtf_output.ScrollToEnd();
                    SubscribeAll();
                }, null);
            })).Start();
        }
Exemplo n.º 14
0
        private void listbox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!App.Instance.LoginComplete)
            {
                if (listbox1.SelectedIndex != -1)
                {
                    listbox1.SelectedIndex = -1;
                }

                return;
            }

            if (listbox1.SelectedIndex != -1)
            {
                Contact contact = listbox1.SelectedItem as Contact;

                if (Minimum)
                {
                    /*Width = 850;
                     * Left = LastLeft;*/
                    SlideFade.CreateAnimationToMaximum();
                    Minimum = false;

                    App.Instance.OpenChats.Clear();
                    view.Refresh();
                    SlideFade.CreateAnimationInMinimum(listbox1);
                    App.Instance.OpenChats.AddRange(TmpOpenChats);
                    view.Refresh();

                    Topmost = false;
                }

                if (!App.Instance.OpenChats.Contains(contact))
                {
                    App.Instance.OpenChats.Add(contact);
                }

                if (page_Chat.ChattingWith != contact || CurrentPage != "chat")
                {
                    btn_home.BorderThickness     = new Thickness(0);
                    btn_contacts.BorderThickness = new Thickness(0);
                    btn_chat.BorderThickness     = new Thickness(0, 0, 0, 2);
                    btn_settings.BorderThickness = new Thickness(0);

                    SlideFade.StartAnimationIn(page_Chat);

                    page_Home.Visibility     = System.Windows.Visibility.Hidden;
                    page_Contacts.Visibility = System.Windows.Visibility.Hidden;
                    page_Chat.Visibility     = System.Windows.Visibility.Visible;
                    page_Settings.Visibility = System.Windows.Visibility.Hidden;
                }


                page_Chat.StartChattingWith(contact);
                contact.MarkAllMessagesRead();
                Console.WriteLine("ChatWith(\"{0}\");", contact.NickName);
                listbox1.SelectedIndex = -1;

                CurrentPage = "chat";
            }
        }
Exemplo n.º 15
0
        public void Draw(bool Resize = false)
        {
            try
            {
                App.Instance.Dispatcher.Invoke((App.MethodInvoker) delegate
                {
                    List <Control_Contact> controls_to_remove = new List <Control_Contact>();
                    foreach (UIElement element in page_canvas.Children)
                    {
                        controls_to_remove.Add((Control_Contact)element);
                    }

                    if (App.Instance.Contacts.Count > 0)
                    {
                        int ControlsPerRow = 0;
                        int Tmp_i          = 0;
                        while (true)
                        {
                            if (Tmp_i + 257 > this.ActualWidth)
                            {
                                break;
                            }

                            Tmp_i += 257;
                            ControlsPerRow++;
                        }

                        if (Resize && ControlsPerRow == LastControlsPerRow)
                        {
                            return;
                        }

                        LastControlsPerRow = ControlsPerRow;

                        int ContactCount    = 0;
                        Contact LastContact = null;
                        int i = 0;
                        int j = 0;

                        Dictionary <int, Contact> sorted_friends = (from entry in App.Instance.Contacts orderby entry.Value.FullName ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);

                        foreach (Contact contact in sorted_friends.Values)
                        {
                            if (contact.status == Status.Online)
                            {
                                if (MainWindow.Instance.txt_search.Text != "" && !contact.FullName.ToLower().Contains(MainWindow.Instance.txt_search.Text.ToLower()) && !contact.StatusUpdate.ToLower().Contains(MainWindow.Instance.txt_search.Text.ToLower()))
                                {
                                    contact.control.Visibility = System.Windows.Visibility.Collapsed;
                                    controls_to_remove.Remove(contact.control);
                                    continue;
                                }
                                ContactCount++;
                                LastContact = contact;

                                if (i == ControlsPerRow)
                                {
                                    j++;
                                    i = 0;
                                }

                                if (contact.control == null)
                                {
                                    Control_Contact contactControl = new Control_Contact(contact);
                                    contactControl.Height          = 70;
                                    contactControl.Width           = 257;

                                    contact.control = contactControl;

                                    page_canvas.Children.Add(contactControl);
                                }
                                else if (contact.control.Visibility == System.Windows.Visibility.Collapsed)
                                {
                                    contact.control.Visibility = System.Windows.Visibility.Visible;
                                    controls_to_remove.Remove(contact.control);
                                }
                                else
                                {
                                    controls_to_remove.Remove(contact.control);
                                }

                                DynamicCanvas.SetLeft(contact.control, 257 * i);
                                DynamicCanvas.SetTop(contact.control, 70 * j + 10);
                                contact.control.profile_image.BorderBrush = (SolidColorBrush) new BrushConverter().ConvertFromString(contact.status.GetColor());

                                i++;
                            }
                        }
                        foreach (Contact contact in sorted_friends.Values)
                        {
                            if (contact.status == Status.Busy)
                            {
                                if (MainWindow.Instance.txt_search.Text != "" && !contact.FullName.ToLower().Contains(MainWindow.Instance.txt_search.Text.ToLower()) && !contact.StatusUpdate.ToLower().Contains(MainWindow.Instance.txt_search.Text.ToLower()))
                                {
                                    contact.control.Visibility = System.Windows.Visibility.Collapsed;
                                    controls_to_remove.Remove(contact.control);
                                    continue;
                                }
                                ContactCount++;
                                LastContact = contact;

                                if (i == ControlsPerRow)
                                {
                                    j++;
                                    i = 0;
                                }

                                if (contact.control == null)
                                {
                                    Control_Contact contactControl = new Control_Contact(contact);
                                    contactControl.Height          = 70;
                                    contactControl.Width           = 257;

                                    contact.control = contactControl;

                                    page_canvas.Children.Add(contactControl);
                                }
                                else if (contact.control.Visibility == System.Windows.Visibility.Collapsed)
                                {
                                    contact.control.Visibility = System.Windows.Visibility.Visible;
                                    controls_to_remove.Remove(contact.control);
                                }
                                else
                                {
                                    controls_to_remove.Remove(contact.control);
                                }

                                DynamicCanvas.SetLeft(contact.control, 257 * i);
                                DynamicCanvas.SetTop(contact.control, 70 * j + 10);
                                contact.control.profile_image.BorderBrush = (SolidColorBrush) new BrushConverter().ConvertFromString(contact.status.GetColor());

                                i++;
                            }
                        }
                        foreach (Contact contact in sorted_friends.Values)
                        {
                            if (contact.status == Status.Away || contact.status == Status.Afk)
                            {
                                if (MainWindow.Instance.txt_search.Text != "" && !contact.FullName.ToLower().Contains(MainWindow.Instance.txt_search.Text.ToLower()) && !contact.StatusUpdate.ToLower().Contains(MainWindow.Instance.txt_search.Text.ToLower()))
                                {
                                    contact.control.Visibility = System.Windows.Visibility.Collapsed;
                                    controls_to_remove.Remove(contact.control);
                                    continue;
                                }
                                ContactCount++;
                                LastContact = contact;

                                if (i == ControlsPerRow)
                                {
                                    j++;
                                    i = 0;
                                }

                                if (contact.control == null)
                                {
                                    Control_Contact contactControl = new Control_Contact(contact);
                                    contactControl.Height          = 70;
                                    contactControl.Width           = 257;

                                    contact.control = contactControl;

                                    page_canvas.Children.Add(contactControl);
                                }
                                else if (contact.control.Visibility == System.Windows.Visibility.Collapsed)
                                {
                                    contact.control.Visibility = System.Windows.Visibility.Visible;
                                    controls_to_remove.Remove(contact.control);
                                }
                                else
                                {
                                    controls_to_remove.Remove(contact.control);
                                }

                                DynamicCanvas.SetLeft(contact.control, 257 * i);
                                DynamicCanvas.SetTop(contact.control, 70 * j + 10);
                                contact.control.profile_image.BorderBrush = (SolidColorBrush) new BrushConverter().ConvertFromString(contact.status.GetColor());

                                i++;
                            }
                        }
                        foreach (Contact contact in sorted_friends.Values)
                        {
                            if (contact.status == Status.Offline)
                            {
                                if (MainWindow.Instance.txt_search.Text != "" && !contact.FullName.ToLower().Contains(MainWindow.Instance.txt_search.Text.ToLower()) && !contact.StatusUpdate.ToLower().Contains(MainWindow.Instance.txt_search.Text.ToLower()))
                                {
                                    contact.control.Visibility = System.Windows.Visibility.Collapsed;
                                    controls_to_remove.Remove(contact.control);
                                    continue;
                                }
                                ContactCount++;
                                LastContact = contact;

                                if (i == ControlsPerRow)
                                {
                                    j++;
                                    i = 0;
                                }

                                if (contact.control == null)
                                {
                                    Control_Contact contactControl = new Control_Contact(contact);
                                    contactControl.Height          = 70;
                                    contactControl.Width           = 257;

                                    contact.control = contactControl;

                                    page_canvas.Children.Add(contactControl);
                                }
                                else if (contact.control.Visibility == System.Windows.Visibility.Collapsed)
                                {
                                    contact.control.Visibility = System.Windows.Visibility.Visible;
                                    controls_to_remove.Remove(contact.control);
                                }
                                else
                                {
                                    controls_to_remove.Remove(contact.control);
                                }

                                DynamicCanvas.SetLeft(contact.control, 257 * i);
                                DynamicCanvas.SetTop(contact.control, 70 * j + 10);
                                contact.control.profile_image.BorderBrush = (SolidColorBrush) new BrushConverter().ConvertFromString(contact.status.GetColor());

                                i++;
                            }
                        }

                        if (ContactCount == 1 && MainWindow.Instance.txt_search.Text != "" && MainWindow.Instance.txt_search.Text.ToLower() == LastContact.FullName.ToLower())
                        {
                            if (!LastContact.Pending)
                            {
                                MainWindow.Instance.txt_search.Text = "";

                                if (MainWindow.Instance.page_Chat.ChattingWith != LastContact || MainWindow.Instance.CurrentPage != "chat")
                                {
                                    MainWindow.Instance.btn_home.BorderThickness     = new Thickness(0);
                                    MainWindow.Instance.btn_contacts.BorderThickness = new Thickness(0);
                                    MainWindow.Instance.btn_chat.BorderThickness     = new Thickness(0, 0, 0, 2);
                                    MainWindow.Instance.btn_settings.BorderThickness = new Thickness(0);

                                    SlideFade.StartAnimationIn(MainWindow.Instance.page_Chat);

                                    MainWindow.Instance.page_Home.Visibility     = System.Windows.Visibility.Hidden;
                                    MainWindow.Instance.page_Contacts.Visibility = System.Windows.Visibility.Hidden;
                                    MainWindow.Instance.page_Chat.Visibility     = System.Windows.Visibility.Visible;
                                    MainWindow.Instance.page_Settings.Visibility = System.Windows.Visibility.Hidden;
                                }

                                MainWindow.Instance.page_Chat.StartChattingWith(LastContact);
                                if (!App.Instance.OpenChats.Contains(LastContact))
                                {
                                    App.Instance.OpenChats.Add(LastContact);
                                }
                                LastContact.MarkAllMessagesRead();

                                MainWindow.Instance.CurrentPage = "chat";

                                MainWindow.Instance.page_Chat.rtf_input.Focusable = true;
                                FocusManager.SetFocusedElement(MainWindow.Instance.page_Chat, MainWindow.Instance.page_Chat.rtf_input);
                                Keyboard.Focus(MainWindow.Instance.page_Chat.rtf_input);
                            }
                        }
                    }

                    foreach (Control_Contact control in controls_to_remove)
                    {
                        page_canvas.Children.Remove(control);
                    }
                }, null);
            }
            catch { }
        }