This should get you started. What I've done is taken a regular RichTextBox and inherited into a custom control called HexRTBTest. This class has public methods called AddRow and AddRows. Use these to display your data in a three column display, as illustrated in the screenshot you posted.
The control code:
Code:
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class HexRTBTest : RichTextBox
{
private const string rtf_header = @"{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fmodern\fprq1\fcharset0 Courier New;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}";
private const string rtf_color_table = @"{\colortbl ;\red255\green255\blue255;}";
private const string rtf_footer = @"\pard\ltrpar\f1\fs17\par}";
private List<HexRTBRow> rows = new List<HexRTBRow>();
public HexRTBTest()
{
this.MinimumSize = new Size(368, 0);
this.ScrollBars = RichTextBoxScrollBars.ForcedVertical;
this.WordWrap = false;
}
public void AddRow(HexRTBRow item)
{
this.rows.Add(item);
this.DrawResults();
}
public void AddRows(HexRTBRow[] items)
{
this.rows.AddRange(items);
this.DrawResults();
}
// you could add other methods like InsertRow, RemoveRow and so on...
private void DrawResults()
{
this.Clear();
if (rows.Count == 0)
return;
StringBuilder sb = new StringBuilder();
sb.AppendLine(rtf_header);
sb.AppendLine(rtf_color_table);
for (int i = 0; i < rows.Count; i++)
{
if (i == 0)
{
sb.Append(@"\viewkind4\uc1\trowd\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10\brdrcf1 ");
sb.Append(@"\trbrdrl\brdrs\brdrw10\brdrcf1 \trbrdrb\brdrs\brdrw10\brdrcf1 \trbrdrr\brdrs\brdrw10\brdrcf1 ");
sb.Append(@"\clbrdrt\brdrw15\brdrs\clbrdrl\brdrw15\brdrs\clbrdrb\brdrw15\brdrs\clbrdrr\brdrw15\brdrs ");
sb.Append(@"\cellx709\clbrdrt\brdrw15\brdrs\clbrdrl\brdrw15\brdrs\clbrdrb\brdrw15\brdrs\clbrdrr\brdrw15\brdrs ");
sb.Append(@"\cellx3828\clbrdrt\brdrw15\brdrs\clbrdrl\brdrw15\brdrs\clbrdrb\brdrw15\brdrs\clbrdrr\brdrw15\brdrs ");
sb.Append(@"\cellx5103\pard\intbl\ltrpar\f0\fs20 ");
sb.AppendLine(rows[i].column1 + "\\cell " + rows[i].column2 + "\\cell " + rows[i].column3 + "\\cell\\row");
}
else
{
sb.Append(@"\trowd\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10\brdrcf1 ");
sb.Append(@"\trbrdrl\brdrs\brdrw10\brdrcf1 \trbrdrb\brdrs\brdrw10\brdrcf1 ");
sb.Append(@"\trbrdrr\brdrs\brdrw10\brdrcf1 \clbrdrt\brdrw15\brdrs\clbrdrl\brdrw15\brdrs\clbrdrb\brdrw15");
sb.Append(@"\brdrs\clbrdrr\brdrw15\brdrs \cellx709\clbrdrt\brdrw15\brdrs\clbrdrl\brdrw15\brdrs\clbrdrb");
sb.Append(@"\brdrw15\brdrs\clbrdrr\brdrw15\brdrs \cellx3828\clbrdrt\brdrw15\brdrs\clbrdrl\brdrw15\brdrs");
sb.Append(@"\clbrdrb\brdrw15\brdrs\clbrdrr\brdrw15\brdrs \cellx5103\intbl ");
sb.AppendLine(rows[i].column1 + "\\cell " + rows[i].column2 + "\\cell " + rows[i].column3 + "\\cell\\row");
}
}
sb.AppendLine(rtf_footer);
this.Rtf = sb.ToString();
this.SelectionStart = this.Text.Length;
}
}
class HexRTBRow
{
public string column1;
public string column2;
public string column3;
public HexRTBRow() { }
public HexRTBRow(string column1, string column2, string column3)
{
this.column1 = column1;
this.column2 = column2;
this.column3 = column3;
}
public override bool Equals(object obj)
{
HexRTBRow blah = (HexRTBRow)obj;
return this.column1 == blah.column1 &&
this.column2 == blah.column2 &&
this.column3 == blah.column3;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
And then to test it, create a form, and then add an instance of HexRTBTest via the VS toolbox (should be up at the top).
Code:
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// test
HexRTBRow[] rows = new HexRTBRow[100];
HexRTBRow test = new HexRTBRow("0058", "5C 00 41 00 70 00 70 00", "\\.A.p.p.");
for (int i = 0; i < rows.Length; i++)
rows[i] = test;
hexRTBTest1.AddRows(rows);
}
}
}