MarkdownViewerHtmlPanel.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using TheArtOfDev.HtmlRenderer.WinForms;
  2. /// <summary>
  3. ///
  4. /// </summary>
  5. namespace com.insanitydesign.MarkdownViewerPlusPlus.Forms
  6. {
  7. /// <summary>
  8. ///
  9. /// </summary>
  10. public class MarkdownViewerHtmlPanel : HtmlPanel
  11. {
  12. /// <summary>
  13. ///
  14. /// </summary>
  15. public MarkdownViewerHtmlPanel()
  16. {
  17. this.AllowDrop = false;
  18. this.Dock = System.Windows.Forms.DockStyle.Fill;
  19. this.IsContextMenuEnabled = false;
  20. this.Location = new System.Drawing.Point(0, 24);
  21. this.MinimumSize = new System.Drawing.Size(20, 20);
  22. this.Name = "markdownViewerHtmlPanel";
  23. this.Size = new System.Drawing.Size(284, 237);
  24. this.TabIndex = 0;
  25. this.AvoidImagesLateLoading = false;
  26. }
  27. /// <summary>
  28. ///
  29. /// </summary>
  30. public override string Text {
  31. get { return _text; }
  32. set {
  33. _text = value;
  34. if (!IsDisposed)
  35. {
  36. _htmlContainer.SetHtml(_text, _baseCssData);
  37. Redraw();
  38. }
  39. }
  40. }
  41. /// <summary>
  42. /// Scroll by the given ratio, calculated with max and page
  43. /// </summary>
  44. /// <param name="scrollRatio"></param>
  45. public void ScrollByRatioVertically(double scrollRatio)
  46. {
  47. if (!IsDisposed)
  48. {
  49. VerticalScroll.Value = (int)((VerticalScroll.Maximum - VerticalScroll.LargeChange) * scrollRatio);
  50. Redraw();
  51. }
  52. }
  53. /// <summary>
  54. ///
  55. /// </summary>
  56. protected void Redraw()
  57. {
  58. PerformLayout();
  59. Invalidate();
  60. InvokeMouseMove();
  61. }
  62. }
  63. }