EditHtmlForm.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #region Using directives
  2. using System.Windows.Forms;
  3. #endregion
  4. namespace WinHtmlEditor
  5. {
  6. /// <summary>
  7. /// Form used to Edit or View Html contents
  8. /// If a property RedOnly is true contents are considered viewable
  9. /// No Html parsing is performed on the resultant data
  10. /// </summary>
  11. internal partial class EditHtmlForm : Form
  12. {
  13. // read only property for the form
  14. private bool _readOnly;
  15. // string values for the form title
  16. private const string editCommand = "È¡Ïû";
  17. private const string viewCommand = "¹Ø±Õ";
  18. /// <summary>
  19. /// Public Form constructor
  20. /// </summary>
  21. public EditHtmlForm()
  22. {
  23. //
  24. // Required for Windows Form Designer support
  25. //
  26. InitializeComponent();
  27. // ensure content is empty
  28. this.htmlText.Text = string.Empty;
  29. this.htmlText.MaxLength = int.MaxValue;
  30. this.ReadOnly = true;
  31. } //EditHtmlForm
  32. /// <summary>
  33. /// Property to modify the caption of the display
  34. /// </summary>
  35. public void SetCaption(string caption)
  36. {
  37. this.Text = caption;
  38. }
  39. /// <summary>
  40. /// Property to set and get the HTML contents
  41. /// </summary>
  42. public string HTML
  43. {
  44. get
  45. {
  46. return this.htmlText.Text.Trim();
  47. }
  48. set
  49. {
  50. this.htmlText.Text = (!value.IsNull())?value.Trim():string.Empty;
  51. this.htmlText.SelectionStart = 0;
  52. this.htmlText.SelectionLength = 0;
  53. }
  54. } //HTML
  55. /// <summary>
  56. /// Property that determines if the html is editable
  57. /// </summary>
  58. public bool ReadOnly
  59. {
  60. get
  61. {
  62. return _readOnly;
  63. }
  64. set
  65. {
  66. _readOnly = value;
  67. this.bOK.Visible = !_readOnly;
  68. this.htmlText.ReadOnly = _readOnly;
  69. this.bCancel.Text = _readOnly?viewCommand:editCommand;
  70. }
  71. }//ReadOnly
  72. private void htmlText_KeyDown(object sender, KeyEventArgs e)
  73. {
  74. var txtBox = sender as TextBox;
  75. if (txtBox != null && txtBox.Multiline && e.Control && e.KeyCode == Keys.A)
  76. {
  77. txtBox.SelectAll();
  78. e.SuppressKeyPress = true;
  79. }
  80. }
  81. }
  82. }