private void MainForm_Activated(object sender, EventArgs e) { SendBox.Select(); for (int i = 0; i < m_Children.Count; i++) { if (m_Children[i] != null) { m_Children[i].BringToFront(); m_Children[i].Activate(); } } if (m_Connected == true) { SendButton.Text = "Send"; SendBox.Enabled = true; ClientServerStatus.Text = "Connected on " + "Port " + m_Port; ClientServerStatus.ForeColor = Color.Green; } else { SendButton.Text = "Connect"; SendBox.Enabled = false; ClientServerStatus.Text = "Not Connected"; ClientServerStatus.ForeColor = Color.Red; } }
private void OnKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter && (Keyboard.Modifiers & (ModifierKeys.Control)) == (ModifierKeys.Control)) { // 添加一个换行字符 SendBox.SelectedText = Environment.NewLine; // 光标向前移动一位 SendBox.Select(SendBox.SelectionStart + 1, 0); e.Handled = true; } else if (e.Key == Key.Enter) { Send(null, null); e.Handled = true; } }