private void DisplayFileContentsText(RpfFileEntry rfe, byte[] data, int length, int offset) { if (data == null) { Cursor = Cursors.Default; DataTextBox.Text = "[Error extracting file! " + rfe.File.LastError + "]"; return; } int selline = -1; int selstartc = -1; int selendc = -1; if (DataHexRadio.Checked) { int charsperln = int.Parse(DataHexLineCombo.Text); int lines = (data.Length / charsperln) + (((data.Length % charsperln) > 0) ? 1 : 0); StringBuilder hexb = new StringBuilder(); StringBuilder texb = new StringBuilder(); StringBuilder finb = new StringBuilder(); if (offset > 0) { selline = offset / charsperln; } for (int i = 0; i < lines; i++) { int pos = i * charsperln; int poslim = pos + charsperln; hexb.Clear(); texb.Clear(); hexb.AppendFormat("{0:X4}: ", pos); for (int c = pos; c < poslim; c++) { if (c < data.Length) { byte b = data[c]; hexb.AppendFormat("{0:X2} ", b); if (char.IsControl((char)b)) { texb.Append("."); } else { texb.Append(Encoding.ASCII.GetString(data, c, 1)); } } else { hexb.Append(" "); texb.Append(" "); } } if (i == selline) { selstartc = finb.Length; } finb.AppendLine(hexb.ToString() + "| " + texb.ToString()); if (i == selline) { selendc = finb.Length - 1; } } DataTextBox.Text = finb.ToString(); } else { string text = Encoding.UTF8.GetString(data); DataTextBox.Text = text; if (offset > 0) { selstartc = offset; selendc = offset + length; } } if ((selstartc > 0) && (selendc > 0)) { DataTextBox.SelectionStart = selstartc; DataTextBox.SelectionLength = selendc - selstartc; DataTextBox.ScrollToCaret(); } }
//print handler for text got from serialPort1_DataReceived function private void DisplayText(object o, EventArgs e) { //print text to datatextbox DataTextBox.AppendText(rxString); DataTextBox.ScrollToCaret(); }