![]()
private void FileExit(object sender, EventArgs e)
{
this.Close();
}
|
private void HelpAbout(object sender, EventArgs e)
{
MessageBox.Show("Binary Viewer Ver 1.0 by Maeda Minoru");
}
|
private void FileOpen(object sender, EventArgs e)
{
OpenFile();
Invalidate();
}
|
private void NextPage(object sender, EventArgs e)
{
pos += 256;
GetFile();
}
|
private void PreviousPage(object sender, EventArgs e)
{
if (pos >= 256)
{
pos -= 256;
GetFile();
}
}
|
private void OpenFile()
{
OpenFileDialog opendlg = new OpenFileDialog();
opendlg.Filter = "ファイル|*.txt;*.html;*.htm;*.dat;*.cs;*.c|すべてのファイル (*.*)|*.*" ;
if (opendlg.ShowDialog() == DialogResult.OK)
{
// 選択ファイルを設定
file_name = opendlg.FileName;
pos = 0;
if (!File.Exists(file_name)) //ファイルの有無をチェック
{
MessageBox.Show(file_name, "Input File Error");
return;
}
GetFile();
}
}
|
|
Message="OLE が呼び出される前に、現在のスレッドが Single Thread Apartment (STA) モードに設定されていなければなりません。 |
[STAThread]
public static void Main()
{
|
private void GetFile()
{
FileStream reader = File.Open(file_name, FileMode.Open);
reader.Position = pos;
leng = reader.Read(byt, 0, 256);
reader.Close();
Invalidate();
}
|
private void MyHandler(object sender, PaintEventArgs e)
{ string wstr = "";
int i,j,k;
byte[] wt = new byte[16];
for(i=0; i<leng; i+=16)
{ j = leng-i;
if (j > 16) j = 16;
for(k=0; k<j; k++) wt[k]= byt[i+k];
// オフセット
k = (pos+i) / 2;
wstr += k.ToString("X4");
wstr += ": ";
// 16進
for(k=0; k<j; k++)
{ wstr+= wt[k].ToString("X2");
if (k % 4 == 3) wstr += " ";
}
// 文字
wstr+= " ";
for(k=0; k<j/2; k++)
{ if ((wt[k*2]==0x0D && wt[k*2+1]==0) ||
(wt[k*2]==0x0A && wt[k*2+1]==0))
wstr+= ".";
else
wstr+= (char)(wt[k*2] + (wt[k*2+1]<<8));
}
wstr+= " ";
wstr+= "\r\n";
}
textBox1.Text = wstr;
}
|
![]()
[Next Chapter ↓] Edit Object Class
[Previous Chapter ↑] 16進+文字