Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ByteViewer Class

Displays byte arrays in hexadecimal, ANSI, and Unicode formats.

For a list of all members of this type, see ByteViewer Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.ComponentModel.Design.ByteViewer

[Visual Basic]
Public Class ByteViewer
   Inherits Control
[C#]
public class ByteViewer : Control
[C++]
public __gc class ByteViewer : public Control
[JScript]
public class ByteViewer extends Control

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

ByteViewer provides an interface for viewing hexadecimal, ANSI, and Unicode formatted data.

The DisplayMode enumeration specifies the identifiers that are used to indicate the display mode to use. The Auto display mode selects a default display mode based on the contents of the byte array. ByteViewer uses a simple algorithm to determine what kind of data is stored in the buffer. The hexadecimal Hexdump view displays the hexadecimal values and corresponding byte representations (chars) in a read-only edit box. The default number of columns is 16. The Ansi and Unicode views show the byte array in a read-only edit box. In these views, the a null reference (Nothing in Visual Basic) characters are replaced with Unicode block characters.

Example

[Visual Basic, C#, C++] The following code example hosts a ByteViewer control in a Form and provides an interface to configure and control the ByteViewer.

[Visual Basic] 
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms

Public Class ByteViewerForm
   Inherits System.Windows.Forms.Form
   Private button1 As System.Windows.Forms.Button
   Private button2 As System.Windows.Forms.Button
   Private byteviewer As System.ComponentModel.Design.ByteViewer
   
    Public Sub New()
        ' Initialize the controls other than the ByteViewer.
        InitializeForm()

        ' Initialize the ByteViewer.
        byteviewer = New ByteViewer
        byteviewer.Location = New Point(8, 46)
        byteviewer.Size = New Size(600, 338)
        byteviewer.Anchor = AnchorStyles.Left Or AnchorStyles.Bottom Or AnchorStyles.Top
        byteviewer.SetBytes(New Byte() {})
        Me.Controls.Add(byteviewer)
    End Sub

    ' Show a file selection dialog and cues the byte viewer to 
    ' load the data in a selected file.
    Private Sub loadBytesFromFile(ByVal sender As Object, ByVal e As EventArgs)
        Dim ofd As New OpenFileDialog
        If ofd.ShowDialog() <> DialogResult.OK Then
            Return
        End If
        byteviewer.SetFile(ofd.FileName)
    End Sub

    ' Clear the bytes in the byte viewer.
    Private Sub clearBytes(ByVal sender As Object, ByVal e As EventArgs)
        byteviewer.SetBytes(New Byte() {})
    End Sub

    ' Changes the display mode of the byte viewer according to the 
    ' Text property of the RadioButton sender control.
    Private Sub changeByteMode(ByVal sender As Object, ByVal e As EventArgs)
        Dim rbutton As System.Windows.Forms.RadioButton = _
            CType(sender, System.Windows.Forms.RadioButton)

        Dim mode As DisplayMode
        Select Case rbutton.Text
            Case "ANSI"
                mode = DisplayMode.Ansi
            Case "Hex"
                mode = DisplayMode.Hexdump
            Case "Unicode"
                mode = DisplayMode.Unicode
            Case Else
                mode = DisplayMode.Auto
        End Select

        ' Sets the display mode.
        byteviewer.SetDisplayMode(mode)
    End Sub

    Private Sub InitializeForm()
        Me.SuspendLayout()
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(680, 440)
        Me.MinimumSize = New System.Drawing.Size(660, 400)
        Me.Size = New System.Drawing.Size(680, 440)
        Me.Name = "Byte Viewer Form"
        Me.Text = "Byte Viewer Form"

        Me.button1 = New System.Windows.Forms.Button
        Me.button1.Location = New System.Drawing.Point(8, 8)
        Me.button1.Size = New System.Drawing.Size(190, 23)
        Me.button1.Name = "button1"
        Me.button1.Text = "Set Bytes From File..."
        Me.button1.TabIndex = 0
        AddHandler Me.button1.Click, AddressOf Me.loadBytesFromFile
        Me.Controls.Add(Me.button1)

        Me.button2 = New System.Windows.Forms.Button
        Me.button2.Location = New System.Drawing.Point(198, 8)
        Me.button2.Size = New System.Drawing.Size(190, 23)
        Me.button2.Name = "button2"
        Me.button2.Text = "Clear Bytes"
        AddHandler Me.button2.Click, AddressOf Me.clearBytes
        Me.button2.TabIndex = 1

        Me.Controls.Add(Me.button2)

        Dim group As New System.Windows.Forms.GroupBox
        group.Location = New Point(418, 3)
        group.Size = New Size(220, 36)
        group.Text = "Display Mode"
        Me.Controls.Add(group)

        Dim rbutton1 As New System.Windows.Forms.RadioButton
        rbutton1.Location = New Point(6, 15)
        rbutton1.Size = New Size(46, 16)
        rbutton1.Text = "Auto"
        rbutton1.Checked = True
        AddHandler rbutton1.Click, AddressOf Me.changeByteMode
        group.Controls.Add(rbutton1)

        Dim rbutton2 As New System.Windows.Forms.RadioButton
        rbutton2.Location = New Point(54, 15)
        rbutton2.Size = New Size(50, 16)
        rbutton2.Text = "ANSI"
        AddHandler rbutton2.Click, AddressOf Me.changeByteMode
        group.Controls.Add(rbutton2)

        Dim rbutton3 As New System.Windows.Forms.RadioButton
        rbutton3.Location = New Point(106, 15)
        rbutton3.Size = New Size(46, 16)
        rbutton3.Text = "Hex"
        AddHandler rbutton3.Click, AddressOf Me.changeByteMode
        group.Controls.Add(rbutton3)

        Dim rbutton4 As New System.Windows.Forms.RadioButton
        rbutton4.Location = New Point(152, 15)
        rbutton4.Size = New Size(64, 16)
        rbutton4.Text = "Unicode"
        AddHandler rbutton4.Click, AddressOf Me.changeByteMode
        group.Controls.Add(rbutton4)
        Me.ResumeLayout(False)
    End Sub

    <STAThread()> _
    Shared Sub Main()
        Application.Run(New ByteViewerForm)
    End Sub
End Class

[C#] 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;

namespace ByteViewerForm
{
    public class ByteViewerForm : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.ComponentModel.Design.ByteViewer byteviewer;

        public ByteViewerForm()
        {
            // Initialize the controls other than the ByteViewer.
            InitializeForm();
            
            // Initialize the ByteViewer.
            byteviewer = new ByteViewer();
            byteviewer.Location = new Point( 8, 46 );
            byteviewer.Size = new Size( 600, 338 );
            byteviewer.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            byteviewer.SetBytes( new byte[] { } );
            this.Controls.Add( byteviewer );
        }

        // Show a file selection dialog and cues the byte viewer to 
        // load the data in a selected file.
        private void loadBytesFromFile(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if( ofd.ShowDialog() != DialogResult.OK )
                return;
            
            byteviewer.SetFile(ofd.FileName);
        }

        // Clear the bytes in the byte viewer.
        private void clearBytes(object sender, EventArgs e)
        {
            byteviewer.SetBytes( new byte[] { } );
        }

        // Changes the display mode of the byte viewer according to the 
        // Text property of the RadioButton sender control.
        private void changeByteMode(object sender, EventArgs e)
        {
            System.Windows.Forms.RadioButton rbutton = 
                (System.Windows.Forms.RadioButton)sender;
            
            DisplayMode mode;           
            switch( rbutton.Text )
            {
                case "ANSI":
                    mode = DisplayMode.Ansi;
                    break;
                case "Hex":
                    mode = DisplayMode.Hexdump;
                    break;
                case "Unicode":
                    mode = DisplayMode.Unicode;
                    break;
                default:
                    mode = DisplayMode.Auto;
                    break;
            }
            
            // Sets the display mode.
            byteviewer.SetDisplayMode( mode );
        }

        private void InitializeForm()
        {
            this.SuspendLayout();
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(680, 440);
            this.MinimumSize = new System.Drawing.Size(660, 400);
            this.Size = new System.Drawing.Size(680, 440);
            this.Name = "Byte Viewer Form";
            this.Text = "Byte Viewer Form";            
            
            this.button1 = new System.Windows.Forms.Button();            
            this.button1.Location = new System.Drawing.Point(8, 8);
            this.button1.Size = new System.Drawing.Size(190, 23);
            this.button1.Name = "button1";
            this.button1.Text = "Set Bytes From File...";            
            this.button1.TabIndex = 0;
            this.button1.Click += new EventHandler(this.loadBytesFromFile);
            this.Controls.Add(this.button1);

            this.button2 = new System.Windows.Forms.Button();            
            this.button2.Location = new System.Drawing.Point(198, 8);
            this.button2.Size = new System.Drawing.Size(190, 23);
            this.button2.Name = "button2";
            this.button2.Text = "Clear Bytes";     
            this.button2.Click += new EventHandler(this.clearBytes);
            this.button2.TabIndex = 1;
            
            this.Controls.Add(this.button2);

            System.Windows.Forms.GroupBox group = new System.Windows.Forms.GroupBox();
            group.Location = new Point(418, 3);
            group.Size = new Size(220, 36);
            group.Text = "Display Mode";
            this.Controls.Add( group );

            System.Windows.Forms.RadioButton rbutton1 = new System.Windows.Forms.RadioButton();
            rbutton1.Location = new Point(6, 15);
            rbutton1.Size = new Size(46, 16);
            rbutton1.Text = "Auto";
            rbutton1.Checked = true;
            rbutton1.Click += new EventHandler(this.changeByteMode);
            group.Controls.Add( rbutton1 );

            System.Windows.Forms.RadioButton rbutton2 = new System.Windows.Forms.RadioButton();
            rbutton2.Location = new Point(54, 15);
            rbutton2.Size = new Size(50, 16);
            rbutton2.Text = "ANSI";
            rbutton2.Click += new EventHandler(this.changeByteMode);
            group.Controls.Add( rbutton2 );

            System.Windows.Forms.RadioButton rbutton3 = new System.Windows.Forms.RadioButton();
            rbutton3.Location = new Point(106, 15);
            rbutton3.Size = new Size(46, 16);
            rbutton3.Text = "Hex";
            rbutton3.Click += new EventHandler(this.changeByteMode);
            group.Controls.Add( rbutton3 );

            System.Windows.Forms.RadioButton rbutton4 = new System.Windows.Forms.RadioButton();
            rbutton4.Location = new Point(152, 15);
            rbutton4.Size = new Size(64, 16);
            rbutton4.Text = "Unicode";
            rbutton4.Click += new EventHandler(this.changeByteMode);
            group.Controls.Add( rbutton4 );
            this.ResumeLayout(false);            
        }

        [STAThread]
        static void Main() 
        {
            Application.Run(new ByteViewerForm());
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Design.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Windows::Forms;

public __gc class ByteViewerForm : public System::Windows::Forms::Form
{
private:
   System::Windows::Forms::Button* button1;
   System::Windows::Forms::Button* button2;
   System::ComponentModel::Design::ByteViewer* byteviewer;

public:
   ByteViewerForm()
   {
      // Initialize the controls other than the ByteViewer.
      InitializeForm();

      // Initialize the ByteViewer.
      byteviewer = new ByteViewer();
      byteviewer->Location = Point( 8, 46 );
      byteviewer->Size = System::Drawing::Size( 600, 338 );
      byteviewer->Anchor =
         static_cast<AnchorStyles>( AnchorStyles::Left | AnchorStyles::Bottom | AnchorStyles::Top );
      byteviewer->SetBytes( (Byte[])Array::CreateInstance( __typeof(Byte), 0 ) );
      this->Controls->Add( byteviewer );
   }

   // Show a file selection dialog and cues the byte viewer to 
   // load the data in a selected file.
private:
   void loadBytesFromFile(Object* /*sender*/, EventArgs* /*e*/)
   {
      OpenFileDialog* ofd = new OpenFileDialog();
      if( ofd->ShowDialog() != DialogResult::OK )
         return;

      byteviewer->SetFile(ofd->FileName);
   }

   // Clear the bytes in the byte viewer.
   void clearBytes(Object* /*sender*/, EventArgs* /*e*/)
   {
      byteviewer->SetBytes( (Byte[])Array::CreateInstance( __typeof(Byte), 0 ) );
   }

   // Changes the display mode of the byte viewer according to the 
   // Text property of the RadioButton sender control.
   void changeByteMode(Object* sender, EventArgs* /*e*/)
   {
      System::Windows::Forms::RadioButton* rbutton = 
         dynamic_cast<System::Windows::Forms::RadioButton*>(sender);

      DisplayMode mode;           
      if( rbutton->Text->Equals(S"ANSI") ){
         mode = DisplayMode::Ansi;
      } else if( rbutton->Text->Equals(S"Hex" ) ) {
         mode = DisplayMode::Hexdump;
      } else if( rbutton->Text->Equals(S"Unicode" ) ) {
         mode = DisplayMode::Unicode;
      } else {
         mode = DisplayMode::Auto;
      }

      // Sets the display mode.
      byteviewer->SetDisplayMode( mode );
   }

   void InitializeForm()
   {
      this->SuspendLayout();
      this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
      this->ClientSize = System::Drawing::Size(680, 440);
      this->MinimumSize = System::Drawing::Size(660, 400);
      this->Size = System::Drawing::Size(680, 440);
      this->Name = S"Byte Viewer Form";
      this->Text = S"Byte Viewer Form";            

      this->button1 = new System::Windows::Forms::Button();            
      this->button1->Location = System::Drawing::Point(8, 8);
      this->button1->Size = System::Drawing::Size(190, 23);
      this->button1->Name = S"button1";
      this->button1->Text = S"Set Bytes From File...";            
      this->button1->TabIndex = 0;
      this->button1->Click += new EventHandler(this, &ByteViewerForm::loadBytesFromFile);
      this->Controls->Add(this->button1);

      this->button2 = new System::Windows::Forms::Button();            
      this->button2->Location = System::Drawing::Point(198, 8);
      this->button2->Size = System::Drawing::Size(190, 23);
      this->button2->Name = S"button2";
      this->button2->Text = S"Clear Bytes";     
      this->button2->Click += new EventHandler(this, &ByteViewerForm::clearBytes);
      this->button2->TabIndex = 1;

      this->Controls->Add(this->button2);

      System::Windows::Forms::GroupBox* group = new System::Windows::Forms::GroupBox();
      group->Location = Point(418, 3);
      group->Size = System::Drawing::Size(220, 36);
      group->Text = S"Display Mode";
      this->Controls->Add( group );

      System::Windows::Forms::RadioButton* rbutton1 = new System::Windows::Forms::RadioButton();
      rbutton1->Location = Point(6, 15);
      rbutton1->Size = System::Drawing::Size(46, 16);
      rbutton1->Text = S"Auto";
      rbutton1->Checked = true;
      rbutton1->Click += new EventHandler(this, &ByteViewerForm::changeByteMode);
      group->Controls->Add( rbutton1 );

      System::Windows::Forms::RadioButton* rbutton2 = new System::Windows::Forms::RadioButton();
      rbutton2->Location = Point(54, 15);
      rbutton2->Size = System::Drawing::Size(50, 16);
      rbutton2->Text = S"ANSI";
      rbutton2->Click += new EventHandler(this, &ByteViewerForm::changeByteMode);
      group->Controls->Add( rbutton2 );

      System::Windows::Forms::RadioButton* rbutton3 = new System::Windows::Forms::RadioButton();
      rbutton3->Location = Point(106, 15);
      rbutton3->Size = System::Drawing::Size(46, 16);
      rbutton3->Text = S"Hex";
      rbutton3->Click += new EventHandler(this, &ByteViewerForm::changeByteMode);
      group->Controls->Add( rbutton3 );

      System::Windows::Forms::RadioButton* rbutton4 = new System::Windows::Forms::RadioButton();
      rbutton4->Location = Point(152, 15);
      rbutton4->Size = System::Drawing::Size(64, 16);
      rbutton4->Text = S"Unicode";
      rbutton4->Click += new EventHandler(this, &ByteViewerForm::changeByteMode);
      group->Controls->Add( rbutton4 );
      this->ResumeLayout(false);            
   }

};

[STAThread]
int main() 
{
   Application::Run(new ByteViewerForm());
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel.Design

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Design (in System.Design.dll)

See Also

ByteViewer Members | System.ComponentModel.Design Namespace | DisplayMode

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft