Barguast
Aug 19th, 2004, 10:27 AM
I'm new to C#, and the first program that I'm doing is a clone of Notepad. This basically consists of a TextBox control docked on a form.
All was going well until I tried to open something other than a text file (namely a bitmap). The problem is that certain characters ('\0' for example) won't display, and worse still won't allow any other characters to appear after them.
I think this is a limitation of the TextBox control, but I'm not sure. This is how I'm reading the file data:
BinaryReader file = new BinaryReader (File.Open (dlgOpenFile.FileName, FileMode.Open, FileAccess.Read));
byte [] buffer = new byte [1024];
while (file.BaseStream.Position != file.BaseStream.Length)
{
int bytesRead = file.Read (buffer, 0, 1024);
string text = System.Text.Encoding.ASCII.GetString (buffer, 0, bytesRead);
txtText.Text += text;
}
file.Close ();
This seems to read the file data properly, but when it is added to the TextBox (txtText) object, it all seems to go wrong.
So, am I reading the file properly? Is the textbox control capable of displaying these characters? Does anyone know where I'm going wrong? :D
Thanks.
All was going well until I tried to open something other than a text file (namely a bitmap). The problem is that certain characters ('\0' for example) won't display, and worse still won't allow any other characters to appear after them.
I think this is a limitation of the TextBox control, but I'm not sure. This is how I'm reading the file data:
BinaryReader file = new BinaryReader (File.Open (dlgOpenFile.FileName, FileMode.Open, FileAccess.Read));
byte [] buffer = new byte [1024];
while (file.BaseStream.Position != file.BaseStream.Length)
{
int bytesRead = file.Read (buffer, 0, 1024);
string text = System.Text.Encoding.ASCII.GetString (buffer, 0, bytesRead);
txtText.Text += text;
}
file.Close ();
This seems to read the file data properly, but when it is added to the TextBox (txtText) object, it all seems to go wrong.
So, am I reading the file properly? Is the textbox control capable of displaying these characters? Does anyone know where I'm going wrong? :D
Thanks.