TablePropertyForm.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #region Using directives
  2. using System;
  3. using System.Windows.Forms;
  4. #endregion
  5. namespace WinHtmlEditor
  6. {
  7. /// <summary>
  8. /// Form used to enter an Html Table structure
  9. /// Input based on the HtmlTableProperty struct
  10. /// </summary>
  11. internal partial class TablePropertyForm : Form
  12. {
  13. // private variable for the table properties
  14. private HtmlTableProperty tableProperties;
  15. // constants for the Maximum values
  16. private const byte MAXIMUM_CELL_ROW = 250;
  17. private const byte MAXIMUM_CELL_COL = 50;
  18. private const byte MAXIMUM_CELL_PAD = 25;
  19. private const byte MAXIMUM_BORDER = 25;
  20. private const ushort MAXIMUM_WIDTH_PERCENT = 100;
  21. private const ushort MAXIMUM_WIDTH_PIXEL = 2500;
  22. private const ushort WIDTH_INC_DIV = 20;
  23. /// <summary>
  24. /// Default form constructor
  25. /// </summary>
  26. public TablePropertyForm()
  27. {
  28. //
  29. // Required for Windows Form Designer support
  30. //
  31. InitializeComponent();
  32. // define the dropdown list value
  33. this.listCaptionAlignment.Items.AddRange(Enum.GetNames(typeof(HorizontalAlignOption)));
  34. this.listCaptionLocation.Items.AddRange(Enum.GetNames(typeof(VerticalAlignOption)));
  35. this.listTextAlignment.Items.AddRange(Enum.GetNames(typeof(HorizontalAlignOption)));
  36. // ensure default values are listed in the drop down lists
  37. this.listCaptionAlignment.SelectedIndex = 0;
  38. this.listCaptionLocation.SelectedIndex = 0;
  39. this.listTextAlignment.SelectedIndex = 0;
  40. // define the new maximum values of the dialogs
  41. this.numericBorderSize.Maximum = MAXIMUM_BORDER;
  42. this.numericCellPadding.Maximum = MAXIMUM_CELL_PAD;
  43. this.numericCellSpacing.Maximum = MAXIMUM_CELL_PAD;
  44. this.numericRows.Maximum = MAXIMUM_CELL_ROW;
  45. this.numericColumns.Maximum = MAXIMUM_CELL_COL;
  46. this.numericTableWidth.Maximum = MAXIMUM_WIDTH_PIXEL;
  47. // define default values based on a new table
  48. this.TableProperties = new HtmlTableProperty(true);
  49. } //TablePropertyForm
  50. /// <summary>
  51. /// Property definition for the Table Properties
  52. /// Uses the HtmlTableProperty class definition
  53. /// </summary>
  54. /// <value></value>
  55. public HtmlTableProperty TableProperties
  56. {
  57. get
  58. {
  59. // define the appropriate table caption properties
  60. tableProperties.CaptionText = this.textTableCaption.Text;
  61. tableProperties.CaptionAlignment = (HorizontalAlignOption)this.listCaptionAlignment.SelectedIndex;
  62. tableProperties.CaptionLocation = (VerticalAlignOption)this.listCaptionLocation.SelectedIndex;
  63. // define the appropriate table specific properties
  64. tableProperties.BorderSize = (byte)Math.Min(this.numericBorderSize.Value, this.numericBorderSize.Maximum);
  65. tableProperties.TableAlignment = (HorizontalAlignOption)this.listTextAlignment.SelectedIndex;
  66. // define the appropriate table layout properties
  67. tableProperties.TableRows = (byte)Math.Min(this.numericRows.Value, this.numericRows.Maximum);
  68. tableProperties.TableColumns = (byte)Math.Min(this.numericColumns.Value, this.numericColumns.Maximum);
  69. tableProperties.CellPadding = (byte)Math.Min(this.numericCellPadding.Value, this.numericCellPadding.Maximum);
  70. tableProperties.CellSpacing = (byte)Math.Min(this.numericCellSpacing.Value, this.numericCellSpacing.Maximum);
  71. tableProperties.TableWidth = (ushort)Math.Min(this.numericTableWidth.Value, this.numericTableWidth.Maximum);
  72. tableProperties.TableWidthMeasurement = (this.radioWidthPercent.Checked) ? MeasurementOption.Percent : MeasurementOption.Pixel;
  73. // return the properties
  74. return tableProperties;
  75. }
  76. set
  77. {
  78. // persist the new values
  79. tableProperties = value;
  80. // define the dialog caption properties
  81. this.textTableCaption.Text = tableProperties.CaptionText;
  82. this.listCaptionAlignment.SelectedIndex = (int)tableProperties.CaptionAlignment;
  83. this.listCaptionLocation.SelectedIndex = (int)tableProperties.CaptionLocation;
  84. // define the dialog table specific properties
  85. this.numericBorderSize.Value = Math.Min(tableProperties.BorderSize, MAXIMUM_BORDER);
  86. this.listTextAlignment.SelectedIndex = (int)tableProperties.TableAlignment;
  87. // define the dialog table layout properties
  88. this.numericRows.Value = Math.Min(tableProperties.TableRows, MAXIMUM_CELL_ROW);
  89. this.numericColumns.Value = Math.Min(tableProperties.TableColumns, MAXIMUM_CELL_COL);
  90. this.numericCellPadding.Value = Math.Min(tableProperties.CellPadding, MAXIMUM_CELL_PAD);
  91. this.numericCellSpacing.Value = Math.Min(tableProperties.CellSpacing, MAXIMUM_CELL_PAD);
  92. this.radioWidthPercent.Checked = (tableProperties.TableWidthMeasurement == MeasurementOption.Percent);
  93. this.radioWidthPixel.Checked = (tableProperties.TableWidthMeasurement == MeasurementOption.Pixel);
  94. this.numericTableWidth.Value = Math.Min(tableProperties.TableWidth, this.numericTableWidth.Maximum);
  95. }
  96. } //TableProperties
  97. /// <summary>
  98. /// Property for the measurement values based on the selected mesaurment
  99. /// </summary>
  100. private void MeasurementOptionChanged(object sender, System.EventArgs e)
  101. {
  102. // define a dialog for a percentage change
  103. if (this.radioWidthPercent.Checked)
  104. {
  105. this.numericTableWidth.Maximum = MAXIMUM_WIDTH_PERCENT;
  106. this.numericTableWidth.Increment = MAXIMUM_WIDTH_PERCENT / WIDTH_INC_DIV;
  107. }
  108. // define a dialog for a pixel change
  109. if (this.radioWidthPixel.Checked)
  110. {
  111. this.numericTableWidth.Maximum = MAXIMUM_WIDTH_PIXEL;
  112. this.numericTableWidth.Increment = MAXIMUM_WIDTH_PIXEL / WIDTH_INC_DIV;
  113. }
  114. } //MeasurementOptionChanged
  115. }
  116. }