protected override void OnPaint(PaintEventArgs e) { Graphics grfx = e.Graphics; Brush brush = new SolidBrush(ForeColor); FileStream fs; try { fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read, FileShare.Read); } catch { return; } for (int iLine = 0; iLine < ClientSize.Height / Font.Height; iLine++) { byte[] abyBuffer = new byte[16]; int iCount = fs.Read(abyBuffer, 0, 16); string str = HexDump.ComposeLine(16 * iLine, abyBuffer, iCount); grfx.DrawString(str, Font, brush, 0, iLine * Font.Height); } fs.Close(); }
void PanelOnPaint(object obj, PaintEventArgs pea) { Panel panel = (Panel)obj; Graphics grfx = pea.Graphics; Brush brush = new SolidBrush(panel.ForeColor); if (radioChecked == null) { return; } IDataObject data = Clipboard.GetDataObject(); object objClip = data.GetData((string)radioChecked.Tag); if (objClip == null) { return; } else if (objClip.GetType() == typeof(string)) { grfx.DrawString((string)objClip, Font, brush, panel.ClientRectangle); } else if (objClip.GetType() == typeof(string[])) // FileDrop { string str = string.Join("\r\n", (string[])objClip); grfx.DrawString(str, Font, brush, panel.ClientRectangle); } else if (objClip.GetType() == typeof(Bitmap) || objClip.GetType() == typeof(Metafile) || objClip.GetType() == typeof(Image)) { grfx.DrawImage((Image)objClip, 0, 0); } else if (objClip.GetType() == typeof(MemoryStream)) { Stream stream = (Stream)objClip; byte[] abyBuffer = new byte[16]; long lAddress = 0; int iCount; Font font = new Font(FontFamily.GenericMonospace, Font.SizeInPoints); float y = 0; while ((iCount = stream.Read(abyBuffer, 0, 16)) > 0) { string str = HexDump.ComposeLine(lAddress, abyBuffer, iCount); grfx.DrawString(str, font, brush, 0, y); lAddress += 16; y += font.GetHeight(grfx); if (y > panel.Bottom) { break; } } } }