protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.Bytes == null) { return; } using (GraphicResources gr = new GraphicResources(e.Graphics)) { int offset = 0; float y = TopMargin; while (offset < this.Bytes.Length) { // Start a new line. float x = LeftMargin; // Write the offset on the left margin. string offsetText = offset.ToString("X4"); e.Graphics.DrawString(offsetText, gr.Font, gr.BrushForAddress, x, y); x += AddressCount * CharWidth; for (int i = 0; i < BytesPerLine; ++i) { if (offset == this.Bytes.Length) { break; } byte b = this.Bytes[offset]; x += ContentGutter; string bits = ByteAsBitString(b); e.Graphics.DrawString(bits, gr.Font, gr.BrushForNonSelection, x, y); bits = SelectionIntersection(bits, offset); if (bits != null) { e.Graphics.DrawString(bits, gr.Font, gr.BrushForSelection, x, y); } x += 8 * CharWidth; offset++; } y += LineHeight; } } }
private void OnBytesChanged() { if (this.Bytes == null) { return; } using (Graphics g = this.CreateGraphics()) using (GraphicResources gr = new GraphicResources(g)) { SizeF sampleText = g.MeasureString("Wj", gr.Font); LineHeight = sampleText.Height; LineCount = (int)Math.Ceiling((float)this.Bytes.Length / BytesPerLine); this.Height = (int)(LineHeight * LineCount) + TopMargin + BottomMargin; this.CharWidth = sampleText.Width / 2; this.Width = (int)( LeftMargin + AddressCount * CharWidth + ContentGutter + BytesPerLine * CharWidth * 8 + ContentGutter * BytesPerLine + RightMargin); } }