private void CheckBoxClicked(object sender, RoutedEventArgs e) { if ((bool)passwordRequired.IsChecked) { passwordBox = new PasswordBox(); passwordBox.Name = "passwordBox"; passwordBox.Margin = new Thickness(3, 4, 0, -7); passwordBox.KeyDown += new System.Windows.Input.KeyEventHandler(IPTextBoxKeyDown); passwordBox.ToolTipOpening += new ToolTipEventHandler(PasswordBoxToolTipOpening); passwordBox.MaxLength = 40; passwordBox.MaxWidth = 180; passwordGrid.Children.Add(passwordBox); Grid.SetColumn(passwordBox, 1); passwordBox.SelectAll(); passwordBox.Focus(); } else { passwordGrid.Children.Remove(passwordBox); passwordBox = null; IPTextBox.SelectAll(); IPTextBox.Focus(); } }
public ManuallyConnectDialog(string IP = null, string nick = null, string message = null) { InitializeComponent(); if (message != null) { Grid.SetRow(responsePanel, 3); Label _messageLabel = new Label(); _messageLabel.Content = message; _messageLabel.Foreground = Brushes.Red; _messageLabel.HorizontalContentAlignment = HorizontalAlignment.Center; _messageLabel.Margin = new Thickness(0, 10, 0, -10); mainGrid.Children.Add(_messageLabel); Grid.SetRow(_messageLabel, 2); } if (IP != null) { IPTextBox.Text = IP; IPTextBox.IsEnabled = false; passwordRequired.IsChecked = true; passwordRequired.IsEnabled = false; passwordBox = new PasswordBox(); passwordBox.Name = "passwordBox"; passwordBox.Margin = new Thickness(3, 4, 0, -7); passwordBox.MaxLength = 40; passwordBox.MaxWidth = 180; passwordBox.KeyDown += new System.Windows.Input.KeyEventHandler(IPTextBoxKeyDown); passwordBox.ToolTipOpening += new ToolTipEventHandler(PasswordBoxToolTipOpening); passwordGrid.Children.Add(passwordBox); Grid.SetColumn(passwordBox, 1); passwordBox.SelectAll(); passwordBox.Focus(); } if (nick != null) { IPTextBox.Width = 150; Label _label = new Label(); if (nick.Length > 10) { nick = nick.Substring(0, 8) + ".."; } nick = "(" + nick + ")"; _label.Content = nick; _label.Width = 1000; IPPanel.Children.Add(_label); Grid.SetColumnSpan(IPTextBox, 1); Grid.SetColumn(_label, 1); passwordRequired.IsChecked = true; passwordRequired.IsEnabled = false; passwordBox = new PasswordBox(); passwordBox.Name = "passwordBox"; passwordBox.Margin = new Thickness(3, 4, 0, -7); passwordBox.MaxWidth = 180; passwordBox.KeyDown += new System.Windows.Input.KeyEventHandler(IPTextBoxKeyDown); passwordBox.ToolTipOpening += new ToolTipEventHandler(PasswordBoxToolTipOpening); passwordGrid.Children.Add(passwordBox); passwordBox.MaxLength = 40; Grid.SetColumn(passwordBox, 1); passwordBox.SelectAll(); passwordBox.Focus(); } else { IPTextBox.Text = "Enter IP Address"; IPTextBox.SelectAll(); IPTextBox.Focus(); } IPTextBox.Style = Resources["noError"] as Style; }