Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

A cheap way to display files and hex data

Total Hit ( 4492)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The .NET framework includes a ByteViewer control, that you can use on your own forms to display data stored in a Byte array or in a file. The ByteViewer control can't be added to the control Toolbox, though, so you must instantiate it through code only.

Click here to copy the following block
' IMPORTANT: this code requires a reference to the System.Design.Dll assembly

Dim WithEvents bv As New ByteViewer()

Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
  ' the ByteViewer control has a fixed width
  ' only the height value is used
  bv.Size = New Size(10, 100)
  bv.ForeColor = Color.Blue
  ' the background color doesn't affect the area where
  ' text or hex values are displayed
  bv.BackColor = Color.LightGray
  ' make it visible and display on the parent form
  bv.Visible = True
  Me.Controls.Add(bv)

  ' display the autoexec.bat file in both text and hex mode
  bv.SetFile("c:\autoexec.bat")
  bv.SetDisplayMode(DisplayMode.Ansi)
End Sub

The SetDisplayMode method can take one of the following values: Ansi, Unicode, Hexdump, and Auto. In auto mode the control attempts to determine the display mode automatically.
The DisplayMode.Hexdump value is very useful, in that the control displays both hex values and text. This is especially useful when used with the SetBytes method, that takes a Byte array as an argument:

Click here to copy the following block
' read a file into a Byte array
Dim sr As New System.IO.FileStream("c:\binary.dat", IO.FileMode.Open)
Dim bytes(sr.Length - 1) As Byte
sr.Read(bytes, 0, sr.Length)
sr.Close()

' display in the control
bv.SetBytes(bytes)

Notice that the ByteViewer class inherits from Control and therefore it exposes all the usual properties, methods, and events. However, a few properties don't work as usual. For example, the Width property is ignored and the control is always 633 pixels wide.



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.