📄 hexedit.cs
字号:
///</summary>
///<param name="sender" type="object"></param>
///<param name="e" type="System.Windows.Forms.KeyEventArgs"></param>
///<returns>void</returns>
///<exception cref="System.Exception">Thrown</exception>
///<remarks>
///</remarks>
///<example>How to use this function
///<code>
///</code>
///</example>
///
protected void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
e.Handled = true;
/*
** This allows the back arrow to work
*/
switch(e.KeyCode)
{
default:
e.Handled = false;
break;
case Keys.Left:
m_bIgnorePart = true;
e.Handled = false;
break;
case Keys.Tab:
break;
case Keys.Back:
{
int iPos = 0;
iPos = SelectionStart - 1;
if((-1 != iPos) && (iPos < (m_abyData.Length * 3)))
{
SelectionStart = iPos;
m_bIgnorePart = true;
}
}
break;
case Keys.Return:
{
CharPosition cp = Position;
int iPos = 0;
iPos = LineIndex(cp.LinePos+1);
if((-1 != iPos) && (iPos < (m_abyData.Length * 3)))
{
SelectionStart = iPos;
}
}
break;
case Keys.Delete:
break;
case Keys.Insert:
break;
}
}
}
/*
***************************************************************************
**
** Class: LinkedBox
**
*/
///<summary>
/// This is the Box that links with the hex edit box to show the ASCII
///</summary>
///<remarks>
///</remarks>
///
public class LinkedBox : HexEditBase
{
/*
** Class Local Variables
*/
///<summary>Length of the Data this box should allow</summary>
protected int m_iDataLength = 0;
///<summary></summary>
protected HexEditBox m_edtHex = null;
///<summary></summary>
protected MenuItem m_miCopy = null;
///<summary></summary>
protected MenuItem m_miPaste = null;
/*
***************************************************************************
**
** Function: InitializeComponent
*/
///<summary>
/// The Component specific initialization
///</summary>
///<returns>void</returns>
///
override public void InitializeComponent()
{
/*
** Create the Context menu
*/
m_menuContext = new ContextMenu();
m_miCopy = new MenuItem();
m_miPaste = new MenuItem();
/*
** miCopy
**
*/
m_miCopy.Index = 0;
m_miCopy.Text = "Copy";
m_miCopy.Click += new System.EventHandler(Menu_Copy);
// miPaste
//
m_miPaste.Index = 1;
m_miPaste.Text = "Paste";
m_miPaste.Click += new System.EventHandler(Menu_Paste);
/*
** Add Items to the Context Menu
*/
m_menuContext.MenuItems.AddRange(new System.Windows.Forms.MenuItem[]
{
m_miCopy,
m_miPaste
});
//
// The ritchbox
//
this.AcceptsTab = true;
this.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Name = "rtbHex";
this.TabIndex = 1;
this.ContextMenu = m_menuContext;
this.Text = "";
this.WordWrap = true;
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnKeyPress);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDown);
}
/*
***************************************************************************
**
** Function: Menu_Copy
*/
///<summary>
/// The Copy Menu Item
///</summary>
///<param name="sender" type="object"></param>
///<param name="e" type="System.EventArgs"></param>
///<returns>void</returns>
///
protected void Menu_Copy(object sender, System.EventArgs e)
{
Copy();
}
/*
***************************************************************************
**
** Function: Menu_Paste
*/
///<summary>
/// The Paste Menu Item
///</summary>
///<param name="sender" type="object"></param>
///<param name="e" type="System.EventArgs"></param>
///<returns>void</returns>
///
protected void Menu_Paste(object sender, System.EventArgs e)
{
if(null != m_edtHex)
{
/*
** Save our starting position
*/
int iSave = SelectionStart;
/*
** Figure out where we should start in the Hex window
** and set its position
*/
m_edtHex.SelectionStart = (SelectionStart * 3);
m_edtHex.Menu_PasteASCII(sender, e);
/*
** Put the Data Base
*/
SelectionStart = iSave;
}
}
/*
***************************************************************************
**
** Function: LinkHex
*/
///<summary>
/// Link the Hex box with this display
///</summary>
///<param name="HexEdit" type="HexEdit.HexEditBox"></param>
///<returns>void</returns>
///
public void LinkHex(HexEditBox HexEdit)
{
m_edtHex = HexEdit;
}
/*
***************************************************************************
**
** Function: UpdateDisplay
*/
///<summary>
/// Update the Box with the Bytes in abyData
///</summary>
///<param name="abyData" type="byte[]">Data to Display</param>
///<returns>void</returns>
///
public void UpdateDisplay(byte[] abyData)
{
m_iDataLength = abyData.Length;
StringBuilder sbVar = new StringBuilder(m_iDataLength);
for(int i = 0; i < m_iDataLength; i++)
{
char cData = GetDisplayChar(abyData[i]);
sbVar.Append(cData);
}
/*
** Remove the extra last char
** and display the data
*/
Text = sbVar.ToString();
}
/*
***************************************************************************
**
** Function: UpdateChar
*/
///<summary>
///Used by the HexBox to update us on character changes
///</summary>
///<param name="iPosition" type="int">Position of Change</param>
///<param name="cData" type="char">Character to Display</param>
///<returns>void</returns>
///
public void UpdateChar(int iPosition, char cData)
{
/*
** controled from the call to update to keep
** updates from linked window when we update it
*/
if(!m_bNoUpdate)
{
/*
** Local Variables
*/
string strVar = string.Format("{0}", GetDisplayChar(cData));
SelectionStart = iPosition;
SelectionLength = 1;
SelectedText = strVar;
}
}
/*
***************************************************************************
**
** Function: OnKeyPress
*/
///<summary>
///Process the Key Presses, to keep in the window area
///</summary>
///<param name="sender" type="object"></param>
///<param name="e" type="System.Windows.Forms.KeyPressEventArgs"></param>
///<returns>void</returns>
///
private void OnKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
/*
** Are we still in the real data area,
** if so process if no done to it
*/
if(SelectionStart < m_iDataLength)
{
switch(e.KeyChar)
{
default:
/*
** This forces a Replace instead of a insert
*/
SelectionLength = 1;
if(null != m_edtHex)
{
m_bNoUpdate = true;
m_edtHex.UpdateChar(SelectionStart, e.KeyChar);
m_bNoUpdate = false;
/*
** This places the focus back to our window
** and processes anything ourstanding
*/
System.Windows.Forms.Application.DoEvents();
Focus();
}
break;
case (char)0xD:
case (char)0x8:
e.Handled = true;
break;
case (char)0x9:
e.Handled = true;
if(null != m_edtHex)
{
m_edtHex.Focus();
m_edtHex.SelectionStart = (SelectionStart * 3);
}
break;
}
}
else
{
e.Handled = true;
}
}
/*
***************************************************************************
**
** Function: OnKeyDown
*/
///<summary>
/// To Keep some special keys from being used
///</summary>
///<param name="sender" type="object"></param>
///<param name="e" type="System.Windows.Forms.KeyEventArgs"></param>
///<returns>void</returns>
///
protected void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
e.Handled = true;
/*
** This allows the back arrow to work
*/
switch(e.KeyCode)
{
default:
e.Handled = false;
break;
case Keys.Delete:
break;
case Keys.Insert:
break;
case Keys.Back:
{
int iPos = 0;
iPos = SelectionStart - 1;
if((-1 != iPos) && (iPos < m_iDataLength))
{
SelectionStart = iPos;
}
}
break;
case Keys.Return:
{
CharPosition cp = Position;
int iPos = 0;
iPos = LineIndex(cp.LinePos+1);
if((-1 != iPos) && (iPos < m_iDataLength))
{
SelectionStart = iPos;
}
}
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -