public DecodeWindow() { InitializeComponent(); dataTypeComboBox.SelectedIndex = 0; rtfColours = RtfColour.CreateColourTable(); rtfHeader = RtfColour.CreateRtfHeader(rtfColours); }
/// <summary> /// Find if a marker starts at a given positions, and if it does add a start RTF colour tag /// </summary> /// <param name="position">The current position.</param> /// <param name="sb">The StringBuilder.</param> private bool FindStartMarkers(int position, StringBuilder sb, bool alternate) { var startMarkers = markers.FindAll(delegate(Marker marker) { return(marker.StartPosition == position); }); foreach (var startMarker in startMarkers) { sb.Append(RtfColour.RtfTag(rtfColours, startMarker.ForeColour.Name, alternate ? startMarker.AlternateBackColour.Name : startMarker.BackColour.Name)); alternate = !alternate; } return(alternate); }
private void EncodeDateTime(string text, bool small) { DateTime value; if (DateTime.TryParse(text, out value)) { var sb = new StringBuilder(rtfHeader); string[] dateValue; if (small) { dateValue = DataConverter.EncodeSmallDateTime(value); } else { dateValue = DataConverter.EncodeDateTime(value); } sb.Append(RtfColour.RtfTag(rtfColours, "Blue", "White")); sb.Append(dateValue[0]); sb.Append("} "); sb.Append(RtfColour.RtfTag(rtfColours, "Green", "White")); sb.Append(dateValue[1]); sb.Append("}"); hexTextBox.Rtf = sb.ToString(); sb.Length = 0; sb.Append(rtfHeader); sb.Append(RtfColour.RtfTag(rtfColours, "Blue", "Control")); sb.Append("Time"); sb.Append("} "); sb.Append(RtfColour.RtfTag(rtfColours, "Green", "Control")); sb.Append("Date"); sb.Append("}"); keyTextBox.Rtf = sb.ToString(); } else { hexTextBox.ForeColor = Color.Red; hexTextBox.Text = "N/A"; } }
/// <summary> /// Initializes a new instance of the <see cref="HexViewer"/> class. /// </summary> public HexViewer() { InitializeComponent(); rtfColours = RtfColour.CreateColourTable(); rtfColours.Add(headerColour); rtfColours.Add(offsetColour); rtfHeader = RtfColour.CreateRtfHeader(rtfColours); if (VisualStyleRenderer.IsSupported) { renderer = new VisualStyleRenderer(VisualStyleElement.Header.Item.Normal); } dataRichTextBox.TextSize = TextRenderer.MeasureText("00", new Font("Courier New", 8.25F)); dataRichTextBox.TextLineSize = TextRenderer.MeasureText("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00", new Font("Courier New", 8.25F)); }
/// <summary> /// Creates RTF output for the page /// </summary> /// <param name="targetPage">The target page.</param> /// <returns></returns> private string FormatPageDetails(Page targetPage) { if (targetPage == null) { return(string.Empty); } var alternate = false; var sb = new StringBuilder(); sb.Append(rtfHeader); // Start header sb.Append(RtfColour.RtfTag(rtfColours, Color.Blue.Name, headerColour.Name)); var currentPos = 0; for (var rows = 0; rows < targetPage.PageData.Length / 16; rows++) { for (var cols = 0; cols < 16; cols++) { if (currentPos == 96) { // End Header sb.Append("}"); } if (currentPos == selectedOffset) { sb.Append(@"{\uldb "); } if (currentPos == Page.Size - targetPage.Header.SlotCount * 2) { // Start offset table sb.Append(RtfColour.RtfTag(rtfColours, Color.Green.Name, offsetColour.Name)); } // Start marker/colour tag if (Colourise) { alternate = FindStartMarkers(currentPos, sb, alternate); } // Add the byte sb.Append(DataConverter.ToHexString(targetPage.PageData[currentPos])); // End marker/close colour tag if (Colourise) { FindEndMarkers(currentPos, sb); } if (currentPos == selectedOffset) { sb.Append("}"); } if (cols != 15) { sb.Append(" "); } currentPos++; } sb.Append(RtfLineBreak); } sb.Append("}"); return(sb.ToString()); }