I wrote a fix, to save you time.
Edit: I noticed that I'm only able to paste one line into ConsoleBox when using the KeyDown event to copy the selected text, not sure on a solution just yet.
Code: Select all
KeyDown += KeyDownHandler;
MenuItem[] menuItems = new MenuItem[] { new MenuItem("Copy", new EventHandler(CopyMenuOnClickHandler)) };
logBox.ContextMenu = new ContextMenu(menuItems);
logBox.ContextMenu.Popup += new EventHandler(CopyMenuPopupHandler);
private void KeyDownHandler(object sender, KeyEventArgs e)
{
if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.C))
{
// Check if selection exists and that it's not null
if (logBox.SelectedText.Length > 0)
// Copy the selected text to the Clipboard
Clipboard.SetText(logBox.SelectedText.ToString(), TextDataFormat.Text);
}
}
private void CopyMenuOnClickHandler(object sender, EventArgs e)
{
if (logBox.SelectedText.Length > 0)
Clipboard.SetText(logBox.SelectedText.ToString(), TextDataFormat.Text);
}
private void CopyMenuPopupHandler(object sender, EventArgs e)
{
ContextMenu menu = sender as ContextMenu;
if (menu != null)
{
menu.MenuItems[0].Enabled = (logBox.SelectedText.Length > 0);
}
}