rendered paste bodyusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace Bersirc.UI.Controls
{
public class HistoryTextBox : TextBox
{
private List<string> m_History;
private int m_HistoryIndex;
public string[] History
{
get { return m_History.ToArray(); }
}
public HistoryTextBox()
{
m_History = new List<string>();
m_HistoryIndex = 0;
this.KeyPress += new KeyPressEventHandler(KeyPressHandler);
this.KeyDown += new KeyEventHandler(KeyDownHandler);
}
private void KeyDownHandler(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
if (m_HistoryIndex > 0)
{
m_HistoryIndex--;
Text = m_History[m_HistoryIndex];
}
e.Handled = true;
}
else if (e.KeyCode == Keys.Down)
{
if (m_HistoryIndex < m_History.Count)
{
m_HistoryIndex++;
Text = m_History[m_HistoryIndex - 1];
}
else
{
Text = "";
}
e.Handled = true;
}
}
private void KeyPressHandler(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
{
if (Text != "")
{
m_History.Add(Text);
m_HistoryIndex = m_History.Count;
e.Handled = true;
}
}
}
}
}