public void Paste()
{
if (!CanPaste()) return;
if (_selectionLength > 0)
_byteProvider.DeleteBytes(_bytePos, _selectionLength);
byte[] buffer = null;
IDataObject da = Clipboard.GetDataObject();
if (da.GetDataPresent("BinaryData"))
{
System.IO.MemoryStream ms = (System.IO.MemoryStream)da.GetData("BinaryData");
buffer = new byte[ms.Length];
ms.Read(buffer, 0, buffer.Length);
}
else if (da.GetDataPresent(typeof(string)))
{
string sBuffer = (string)da.GetData(typeof(string));
Regex invalidHex = new Regex("[^0-9A-Fa-f]");
if (!invalidHex.IsMatch(sBuffer) && sBuffer.Length % 2 == 0 && _keyInterpreter == _ki)
{
buffer = new byte[sBuffer.Length / 2];
byte tmp;
for (int i = 0; i < sBuffer.Length; i += 2)
{
if (!byte.TryParse(sBuffer.Substring(i, 2), System.Globalization.NumberStyles.HexNumber, System.Globalization.NumberFormatInfo.CurrentInfo, out tmp))
{
buffer = null;
break;
}
buffer[i / 2] = tmp;
}
}
if(buffer == null)
{
buffer = System.Text.Encoding.ASCII.GetBytes(sBuffer);
}
}
else
{
return;
}
_byteProvider.InsertBytes(_bytePos, buffer);
SetPosition(_bytePos + buffer.Length, 0);
ReleaseSelection();
ScrollByteIntoView();
UpdateCaret();
Invalidate();
}