Thread: HexEdit control

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    244

    HexEdit control

    hi!
    i'm looking for a free HexEdit user control for C#

    it should look something like that:
    http://support.moonpoint.com/os/wind...utlook_ost.png

    it shouldnt be over-complicated and it should be embettable into the project (no dlls)

    do you know where i can find such? i searched, but with no results...
    thanks so far!

  2. #2
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    You could try making your own. It just looks like a RichTextBox using RTF cells to allign the text into columns.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    i don't have the slight idea how to do this so i'm hoping to find a usercontrol somewhere on the web...

  4. #4
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    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);
            }
        }
    }

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    i looked at your code. first, i want to thank you for helping me... but it seems like i can enter anything in there, not just replace the hex values... it somehow doesn't feel like a hexedit...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  2. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 07:58 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM