Public Class frmHex
Dim inputlength As Integer = 20
Dim filelength As Long
Dim topposition As Long
Dim fsin As IO.FileStream
Dim br As IO.BinaryReader, bw As IO.BinaryWriter
Dim WithEvents lboByte As New ListBox With _
{.Parent = Me, .Top = 10, .Height = 300, .Left = 10, .Width = 40}
Dim WithEvents lboHex As New ListBox With _
{.Parent = Me, .Top = 10, .Height = 300, .Left = 50, .Width = 40}
Dim WithEvents lboAsc As New ListBox With _
{.Parent = Me, .Top = 10, .Height = 300, .Left = 100, .Width = 40}
Dim WithEvents txtEdit As New TextBox With _
{.Parent = Me, .Top = 10, .Height = 300, .Left = 150, .Width = 40}
Private Sub frmHex_FormClosing(sender As Object, _
e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
fsin.Close()
End Sub
Private Sub frmHex_Load(sender As System.Object, e As System.EventArgs) _
Handles MyBase.Load
Me.Width = 200 : Me.Height = 350
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
Dim infile As String = "Pfad Dateiname angeben"
fsin = New IO.FileStream(infile, IO.FileMode.Open, _
IO.FileAccess.ReadWrite)
filelength = fsin.Length
br = New IO.BinaryReader(fsin)
bw = New IO.BinaryWriter(fsin)
topposition = 0
Showbytes()
End Sub
Private Sub Showbytes()
fsin.Position = topposition
Dim byt As Byte() = br.ReadBytes(inputlength)
lboByte.SuspendLayout() : lboHex.SuspendLayout() : lboAsc.SuspendLayout( _
)
lboByte.Items.Clear() : lboHex.Items.Clear() : lboAsc.Items.Clear()
For i As Integer = 0 To byt.Length - 1
lboByte.Items.Add(byt(i))
lboHex.Items.Add(Hex(byt(i)))
lboAsc.Items.Add(Chr(byt(i)))
Next i
lboByte.ResumeLayout() : lboHex.ResumeLayout() : lboAsc.ResumeLayout()
End Sub
Private Sub lbo_KeyDown(sender As Object, e As _
System.Windows.Forms.KeyEventArgs) _
Handles lboByte.KeyDown
With lboByte
If e.KeyCode = Keys.Down And .SelectedIndex = .Items.Count - 1 And _
topposition < filelength - inputlength Then
topposition += 1
Showbytes()
.SelectedIndex = .Items.Count - 1
ElseIf e.KeyCode = Keys.Up And .SelectedIndex = 0 And topposition _
> 0 Then
topposition -= 1
Showbytes()
.SelectedIndex = 0
ElseIf e.KeyCode = Keys.Next Then
Dim stepp As Integer = inputlength
If e.Shift Then stepp *= 10
topposition = Math.Min(topposition + stepp, filelength - _
inputlength)
topposition = Math.Max(topposition, 0)
Showbytes()
.SelectedIndex = .Items.Count - 1
ElseIf e.KeyCode = Keys.Prior Then
Dim stepp As Integer = inputlength
If e.Shift Then stepp *= 10
topposition = Math.Max(topposition - stepp, 0)
Showbytes()
ElseIf e.KeyCode = Keys.End Then
topposition = filelength - inputlength
Showbytes()
.SelectedIndex = .Items.Count - 1
ElseIf e.KeyCode = Keys.Home Then
topposition = 0
Showbytes()
.SelectedIndex = .Items.Count - 1
End If
End With
Me.Text = CStr(topposition)
End Sub
Private Sub lbo_GotFocus(sender As Object, e As System.EventArgs) _
Handles lboAsc.GotFocus, lboHex.GotFocus
lboByte.Focus()
End Sub
Private Sub lboByte_SelectedIndexChanged(sender As Object, e As _
System.EventArgs) _
Handles lboByte.SelectedIndexChanged
txtEdit.Text = CStr(lboByte.SelectedItem)
End Sub
Private Sub txtEdit_KeyDown(sender As Object, e As _
System.Windows.Forms.KeyEventArgs) _
Handles txtEdit.KeyDown
If e.KeyCode = Keys.Enter Then
If Not IsNumeric(txtEdit.Text.Trim) Then Return
Dim dbl As Double = CDbl(txtEdit.Text.Trim)
If (dbl < 0 Or dbl > 255) OrElse dbl <> CInt(dbl) Then Return
fsin.Position = topposition + lboByte.SelectedIndex
bw.Write(CByte(dbl))
Showbytes()
End If
End Sub
End Class
Beitrag wurde zuletzt am 11.06.11 um 09:40:20 editiert. |