1

I am trying to reproduce a window from the Microsoft built-in Registry Editor. The window is the one which is opened when you select "Modify Binary Data..." from the context-menu when a value is clicked.

The goal is to make an identical(!) window in my .NET C# application using Windows Forms.

The problem is the textBox displayed in the window which contains the binary data. I have tried using a RichTextBox, but it isn't as simple as it seems to be especially when it comes to editing data and the behaviour of this textBox.

So I have 2 questions:

  1. How to achieve an identical textBox in C# using Windows Forms? Maybe you know some other ways to reproduce this textBox?
  2. I also need the font name used in this textBox, I couldn't find it :)

Thanks!

Darxis
  • 1,482
  • 1
  • 17
  • 37
  • How "identical" does it have to be? Why? – Doc Brown Aug 22 '12 at 05:42
  • Saying identical I mean that every pixel in the windows must matches. Controls must be exact size, same font etc. Why? I've been told to do so. – Darxis Aug 22 '12 at 12:44
  • I ask because for a working solution which behaves very similar (but not identical) the programming effort may be almost zero (see my answer), whilst for an identical control the programming effort may be some days or weeks. And I know only one reason for which one really needs an identical control - if you are going to create a "trojan horse" replacement for the registry editor. So are you going to build somethign like that? – Doc Brown Aug 22 '12 at 12:59
  • Yes I am trying to reproduce the registry editor, but if my goal were to make a trojan horse, I wouldn't have been creating a new application from scratch, but I would have used the existing one, and injected my malicious code into the exe. So my answer is no, I am not making a trojan horse – Darxis Aug 22 '12 at 14:02

2 Answers2

2

I can think of two ways you can approach this. The first is a DataGrid, painstakingly styled to have transparent grid lines and exact margins between columns, with filters to enforce hex digits only. All this, set alongside a richtextbox for the ASCII display, with your code synchronizing the selection between them.

Alternately, you can replace the DataGrid with a collection of TextBoxes, again styled for invisible borders, automatically adding new textboxes to the collection when the user adds more data.

All in all, it seems like an awful lot of work, especially in WinForms - WPF might make this a bit easier, especially the styling, but still a lot of work.

Regarding the name of that control - I tried using Spy++ to sniff it out, and it seems it's registered as a Window Class named "HEX", but I'm not sure that will really get you somewhere:

enter image description here

Avner Shahar-Kashtan
  • 14,492
  • 3
  • 37
  • 63
  • The problem is that I checked how many Controls were used for this "textbox" and there is only one, so I would like to make this using only one Control – Darxis Aug 21 '12 at 19:54
  • One Control? I do not think this means what you think it means. Are you talking WinForms control? Windows control? The word has different meanings in different contexts. Just because the specific editor used in Regedit, which was probably coded in C++/MFC, is built one way doesn't mean a WinForms implementation should too. – Avner Shahar-Kashtan Aug 21 '12 at 20:26
2

Here is an open source project containing a hex editor control for Winforms, looking at least very similar:

http://sourceforge.net/projects/hexbox/

I guess you can modify it accordingly to your requirements. But beware, the source code for the control is ~6000 lines of code (including more than a dozen utility classes). It inherits directly from "Control" and does all the text display using GDI+ (so no modified DataGrid or RichTextBox).

Doc Brown
  • 19,739
  • 7
  • 52
  • 88
  • 1
    I know this project. If you don't want to write your own lightweight usercontrol, it's probably the best option you have. +1 – ken2k Aug 21 '12 at 20:29