Be.Windows.Forms.HexBox.Paste C# (CSharp) 메소드

Paste() 공개 메소드

Replaces the current selection in the hex box with the contents of the Clipboard.
public Paste ( ) : void
리턴 void
        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();
        }

Usage Example

 /// <summary>
 /// The handler for the "Paste"-Click event
 /// </summary>
 /// <param name="sender">the sender object</param>
 /// <param name="e">the event data</param>
 void PasteMenuItem_Click(object sender, EventArgs e)
 {
     _hexBox.Paste();
 }
All Usage Examples Of Be.Windows.Forms.HexBox::Paste
HexBox