Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

ByteViewer Classe

Byte exibe matriz em hexadecimal, ANSI e UniCode formatos.

Namespace:  System.ComponentModel.Design
Assembly:  System.Design (em System.Design. dll)

public class ByteViewer : TableLayoutPanel

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, NUL characters are replaced with Unicode block characters.

The following code example hosts a ByteViewer control in a Form and provides an interface to configure and control the ByteViewer.

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.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());
        }
    }
}



package ByteViewerForm; 

import System.*;
import System.Drawing.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Windows.Forms.*;

public class ByteViewerForm extends 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.set_Location(new Point(8, 46));
        byteViewer.set_Size(new Size(600, 338));
        byteViewer.set_Anchor(
            AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top);
        byteViewer.SetBytes(new ubyte[]{});
        this.get_Controls().Add(byteViewer);
    } //ByteViewerForm

    // 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.get_FileName());
    } //LoadBytesFromFile

    // Clear the bytes in the byte viewer.
    private void ClearBytes(Object sender, EventArgs e)
    {
        byteViewer.SetBytes(new ubyte[]{});
    } //ClearBytes

    // 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;

        if (rbutton.get_Text().Equals("ANSI")) {
            mode = DisplayMode.Ansi;
        }
        else {
            if (rbutton.get_Text().Equals("Hex")) {
                mode = DisplayMode.Hexdump;
            }
            else {
                if (rbutton.get_Text().Equals("Unicode")) {
                    mode = DisplayMode.Unicode;
                }
                else {
                    mode = DisplayMode.Auto;
                }
            }
        }

        // Sets the display mode.
        byteViewer.SetDisplayMode(mode);
    } //ChangeByteMode

    private void InitializeForm()
    {
        this.SuspendLayout();
        this.set_ClientSize(new System.Drawing.Size(680, 440));
        this.set_MinimumSize(new System.Drawing.Size(660, 400));
        this.set_Size(new System.Drawing.Size(680, 440));
        this.set_Name("Byte Viewer Form");
        this.set_Text("Byte Viewer Form");
        this.button1 = new System.Windows.Forms.Button();
        this.button1.set_Location(new System.Drawing.Point(8, 8));
        this.button1.set_Size(new System.Drawing.Size(190, 23));
        this.button1.set_Name("button1");
        this.button1.set_Text("Set Bytes From File...");
        this.button1.set_TabIndex(0);
        this.button1.add_Click(new EventHandler(this.LoadBytesFromFile));
        this.get_Controls().Add(this.button1);
        this.button2 = new System.Windows.Forms.Button();
        this.button2.set_Location(new System.Drawing.Point(198, 8));
        this.button2.set_Size(new System.Drawing.Size(190, 23));
        this.button2.set_Name("button2");
        this.button2.set_Text("Clear Bytes");
        this.button2.add_Click(new EventHandler(this.ClearBytes));
        this.button2.set_TabIndex(1);
        this.get_Controls().Add(this.button2);

        System.Windows.Forms.GroupBox group = 
            new System.Windows.Forms.GroupBox();
        group.set_Location(new Point(418, 3));
        group.set_Size(new Size(220, 36));
        group.set_Text("Display Mode");
        this.get_Controls().Add(group);

        System.Windows.Forms.RadioButton rbutton1 = 
            new System.Windows.Forms.RadioButton();
        rbutton1.set_Location(new Point(6, 15));
        rbutton1.set_Size(new Size(46, 16));
        rbutton1.set_Text("Auto");
        rbutton1.set_Checked(true);
        rbutton1.add_Click(new EventHandler(this.ChangeByteMode));
        group.get_Controls().Add(rbutton1);

        System.Windows.Forms.RadioButton rbutton2 = 
            new System.Windows.Forms.RadioButton();
        rbutton2.set_Location(new Point(54, 15));
        rbutton2.set_Size(new Size(50, 16));
        rbutton2.set_Text("ANSI");
        rbutton2.add_Click(new EventHandler(this.ChangeByteMode));
        group.get_Controls().Add(rbutton2);

        System.Windows.Forms.RadioButton rbutton3 = 
            new System.Windows.Forms.RadioButton();
        rbutton3.set_Location(new Point(106, 15));
        rbutton3.set_Size(new Size(46, 16));
        rbutton3.set_Text("Hex");
        rbutton3.add_Click(new EventHandler(this.ChangeByteMode));
        group.get_Controls().Add(rbutton3);

        System.Windows.Forms.RadioButton rbutton4 = 
            new System.Windows.Forms.RadioButton();
        rbutton4.set_Location(new Point(152, 15));
        rbutton4.set_Size(new Size(64, 16));
        rbutton4.set_Text("Unicode");
        rbutton4.add_Click(new EventHandler(this.ChangeByteMode));
        group.get_Controls().Add(rbutton4);
        this.ResumeLayout(false);
    } //InitializeForm

    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        Application.Run(new ByteViewerForm());
    } //main
} //ByteViewerForm


System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Windows.Forms.Control
        System.Windows.Forms.ScrollableControl
          System.Windows.Forms.Panel
            System.Windows.Forms.TableLayoutPanel
              System.ComponentModel.Design.ByteViewer

Quaisquer membros públicos estático (compartilhados na Visual Basic) desse tipo são Thread seguro. Não há garantia de que qualquer membro de instância seja isento de segmentos.

Contribuições da comunidade

ADICIONAR
Mostrar: