// Buttons: private void Btn_Login_Click(object sender, RoutedEventArgs e) { try { Client.Login(Txt_Email.Text, Txt_Password.Password.ToString()); while (Client.loginstate == false) { } int userId = Client.GetLoginId(); if (userId != -1) { // hide current form this.Hide(); // open new form FormMain form = new FormMain(userId, Client); form.ShowDialog(); // close current form this.Close(); } else { throw new InvalidLoginCombination(); } } catch (InvalidLoginCombination ex) { Lbl_Warning.Content = ex.Message; Lbl_Warning.Visibility = Visibility.Visible; } catch (EmptyField ex) { Lbl_Warning.Content = ex.Message; Lbl_Warning.Visibility = Visibility.Visible; } catch (InvalidEmail ex) { Lbl_Warning.Content = ex.Message; Lbl_Warning.Visibility = Visibility.Visible; } }