BodyView.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // **********************************************************************************
  2. // CassiniDev - http://cassinidev.codeplex.com
  3. //
  4. // Copyright (c) Sky Sanders. All rights reserved.
  5. //
  6. // This source code is subject to terms and conditions of the Microsoft Public
  7. // License (Ms-PL). A copy of the license can be found in the license.htm file
  8. // included in this distribution.
  9. //
  10. // You must not remove this notice, or any other, from this software.
  11. //
  12. // **********************************************************************************
  13. #region
  14. using System;
  15. using System.ComponentModel;
  16. using System.Drawing;
  17. using System.IO;
  18. using System.Text;
  19. using System.Windows.Forms;
  20. #endregion
  21. namespace CassiniDev.ServerLog
  22. {
  23. [DefaultBindingProperty("Value")]
  24. public partial class BodyView : UserControl
  25. {
  26. private byte[] _value;
  27. public BodyView()
  28. {
  29. InitializeComponent();
  30. pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  31. }
  32. public Byte[] Value
  33. {
  34. get { return _value; }
  35. set
  36. {
  37. _value = value;
  38. ClearDisplay();
  39. if (_value != null)
  40. {
  41. HexViewTextBox.Text = _value.ConvertToHexView(8);
  42. TextViewTextBox.Text = Encoding.UTF8.GetString(_value);
  43. try
  44. {
  45. using (MemoryStream s = new MemoryStream(_value))
  46. {
  47. pictureBox1.Image = Image.FromStream(s);
  48. }
  49. pictureBox1.Visible = true;
  50. }
  51. // ReSharper disable EmptyGeneralCatchClause
  52. catch
  53. // ReSharper restore EmptyGeneralCatchClause
  54. {
  55. }
  56. }
  57. }
  58. }
  59. private void ClearDisplay()
  60. {
  61. if (pictureBox1.Image != null)
  62. {
  63. pictureBox1.Image.Dispose();
  64. pictureBox1.Image = null;
  65. }
  66. HexViewTextBox.Text = "";
  67. TextViewTextBox.Text = "";
  68. }
  69. }
  70. }