|
using System;
using System.Windows.Forms;
namespace TenTec.Utils
{
/// <summary>
/// This class is used to edit member fields. It supports
/// additional hot keys and other operations.
/// </summary>
internal class MemberFieldListBox: ListBox
{
/// <summary>
/// Creates a new instance of the MemberFieldListBox class
/// </summary>
public MemberFieldListBox(){}
/// <summary>
/// Processes the hot keys.
/// </summary>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData == (Keys.A | Keys.Control) && SelectionMode == SelectionMode.MultiExtended || SelectionMode == SelectionMode.MultiSimple)
{
SelectAll();
return true;
}
if(keyData == (Keys.C | Keys.Control) || keyData == (Keys.Insert | Keys.Control))
{
OnCopyToClipboard(EventArgs.Empty);
return true;
}
if(keyData == (Keys.V | Keys.Control) || keyData == (Keys.Insert | Keys.Shift))
{
OnPasteFromClipboard(EventArgs.Empty);
return true;
}
return base.ProcessCmdKey (ref msg, keyData);
}
/// <summary>
/// Copies the selected items to the clipboard.
/// </summary>
private void OnCopyToClipboard(EventArgs e)
{
if(CopyToClipboard != null)
CopyToClipboard(this, e);
}
/// <summary>
/// Pastes items from the clipboard.
/// </summary>
private void OnPasteFromClipboard(EventArgs e)
{
if(PasteFromClipboard != null)
PasteFromClipboard(this, e);
}
/// <summary>
/// Selects all the items.
/// </summary>
private void SelectAll()
{
for(int myIndex = 0; myIndex < Items.Count; myIndex++)
SetSelected(myIndex, true);
}
/// <summary>
/// This event is raised when the user presses the Ctrl+C keys.
/// </summary>
public event EventHandler CopyToClipboard;
/// <summary>
/// This event is raised when the user presses the Ctrl+V keys.
/// </summary>
public event EventHandler PasteFromClipboard;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.