C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-24-2009, 12:38 PM   #1
Registered User
 
Join Date: Jan 2008
Posts: 153
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!
Devils Child is offline   Reply With Quote
Old 10-24-2009, 04:50 PM   #2
Registered User
 
Join Date: Mar 2009
Location: england
Posts: 76
You could try making your own. It just looks like a RichTextBox using RTF cells to allign the text into columns.
theoobe is offline   Reply With Quote
Old 10-25-2009, 03:25 AM   #3
Registered User
 
Join Date: Jan 2008
Posts: 153
i don't have the slight idea how to do this so i'm hoping to find a usercontrol somewhere on the web...
Devils Child is offline   Reply With Quote
Old 10-25-2009, 05:33 AM   #4
Registered User
 
Join Date: Mar 2009
Location: england
Posts: 76
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);
        }
    }
}
theoobe is offline   Reply With Quote
Old 10-26-2009, 02:24 AM   #5
Registered User
 
Join Date: Jan 2008
Posts: 153
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...
Devils Child is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 11:23 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22