tablepropertyform.cs
来自「一个很好用的html编辑器。带源码」· CS 代码 · 共 493 行 · 第 1/2 页
CS
493 行
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using HtmlTableProperty = Microsoft.ConsultingServices.HtmlEditor.HtmlTableProperty;
using MeasurementOption = Microsoft.ConsultingServices.HtmlEditor.MeasurementOption;
using HorizontalAlignOption = Microsoft.ConsultingServices.HtmlEditor.HorizontalAlignOption;
using VerticalAlignOption = Microsoft.ConsultingServices.HtmlEditor.VerticalAlignOption;
namespace Microsoft.ConsultingServices.HtmlEditor
{
/// <summary>
/// Form used to enter an Html Table structure
/// Input based on the HtmlTableProperty struct
/// </summary>
internal class TablePropertyForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button bCancel;
private System.Windows.Forms.Button bInsert;
private System.Windows.Forms.TextBox textTableCaption;
private System.Windows.Forms.Label labelCaption;
private System.Windows.Forms.Label labelCaptionAlign;
private System.Windows.Forms.Label labelLocation;
private System.Windows.Forms.GroupBox groupLayout;
private System.Windows.Forms.GroupBox groupCaption;
private System.Windows.Forms.Label labelRowColumn;
private System.Windows.Forms.NumericUpDown numericRows;
private System.Windows.Forms.NumericUpDown numericColumns;
private System.Windows.Forms.Label labelPadding;
private System.Windows.Forms.NumericUpDown numericCellPadding;
private System.Windows.Forms.Label labelSpacing;
private System.Windows.Forms.NumericUpDown numericCellSpacing;
private System.Windows.Forms.Label labelWidth;
private System.Windows.Forms.NumericUpDown numericTableWidth;
private System.Windows.Forms.ComboBox listCaptionAlignment;
private System.Windows.Forms.ComboBox listCaptionLocation;
private System.Windows.Forms.GroupBox groupTable;
private System.Windows.Forms.NumericUpDown numericBorderSize;
private System.Windows.Forms.RadioButton radioWidthPercent;
private System.Windows.Forms.Label labelBorderAlign;
private System.Windows.Forms.Label labelBorderSize;
private System.Windows.Forms.Panel groupPercentPixel;
private System.Windows.Forms.ComboBox listTextAlignment;
private System.Windows.Forms.RadioButton radioWidthPixel;
// private variable for the table properties
private HtmlTableProperty tableProperties;
// constants for the Maximum values
private const byte MAXIMUM_CELL_ROW = 250;
private const byte MAXIMUM_CELL_COL = 50;
private const byte MAXIMUM_CELL_PAD = 25;
private const byte MAXIMUM_BORDER = 25;
private const ushort MAXIMUM_WIDTH_PERCENT = 100;
private const ushort MAXIMUM_WIDTH_PIXEL = 2500;
private const ushort WIDTH_INC_DIV = 20;
// default form constructor
public TablePropertyForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
// define the dropdown list value
this.listCaptionAlignment.Items.AddRange(Enum.GetNames(typeof(HorizontalAlignOption)));
this.listCaptionLocation.Items.AddRange(Enum.GetNames(typeof(VerticalAlignOption)));
this.listTextAlignment.Items.AddRange(Enum.GetNames(typeof(HorizontalAlignOption)));
// ensure default values are listed in the drop down lists
this.listCaptionAlignment.SelectedIndex = 0;
this.listCaptionLocation.SelectedIndex = 0;
this.listTextAlignment.SelectedIndex = 0;
// define the new maximum values of the dialogs
this.numericBorderSize.Maximum = MAXIMUM_BORDER;
this.numericCellPadding.Maximum = MAXIMUM_CELL_PAD;
this.numericCellSpacing.Maximum = MAXIMUM_CELL_PAD;
this.numericRows.Maximum = MAXIMUM_CELL_ROW;
this.numericColumns.Maximum = MAXIMUM_CELL_COL;
this.numericTableWidth.Maximum = MAXIMUM_WIDTH_PIXEL;
// define default values based on a new table
this.TableProperties = new HtmlTableProperty(true);
} //TablePropertyForm
public HtmlTableProperty TableProperties
{
get
{
// define the appropriate table caption properties
tableProperties.CaptionText = this.textTableCaption.Text;
tableProperties.CaptionAlignment = (HorizontalAlignOption)this.listCaptionAlignment.SelectedIndex;
tableProperties.CaptionLocation = (VerticalAlignOption)this.listCaptionLocation.SelectedIndex;
// define the appropriate table specific properties
tableProperties.BorderSize = (byte)Math.Min(this.numericBorderSize.Value, this.numericBorderSize.Maximum);
tableProperties.TableAlignment = (HorizontalAlignOption)this.listTextAlignment.SelectedIndex;
// define the appropriate table layout properties
tableProperties.TableRows = (byte)Math.Min(this.numericRows.Value, this.numericRows.Maximum);
tableProperties.TableColumns = (byte)Math.Min(this.numericColumns.Value, this.numericColumns.Maximum);
tableProperties.CellPadding = (byte)Math.Min(this.numericCellPadding.Value, this.numericCellPadding.Maximum);
tableProperties.CellSpacing = (byte)Math.Min(this.numericCellSpacing.Value, this.numericCellSpacing.Maximum);
tableProperties.TableWidth = (ushort)Math.Min(this.numericTableWidth.Value, this.numericTableWidth.Maximum);
tableProperties.TableWidthMeasurement = (this.radioWidthPercent.Checked) ? MeasurementOption.Percent : MeasurementOption.Pixel;
// return the properties
return tableProperties;
}
set
{
// persist the new values
tableProperties = value;
// define the dialog caption properties
this.textTableCaption.Text = tableProperties.CaptionText;
this.listCaptionAlignment.SelectedIndex = (int)tableProperties.CaptionAlignment;
this.listCaptionLocation.SelectedIndex = (int)tableProperties.CaptionLocation;
// define the dialog table specific properties
this.numericBorderSize.Value = Math.Min(tableProperties.BorderSize, MAXIMUM_BORDER);
this.listTextAlignment.SelectedIndex = (int)tableProperties.TableAlignment;
// define the dialog table layout properties
this.numericRows.Value = Math.Min(tableProperties.TableRows, MAXIMUM_CELL_ROW);
this.numericColumns.Value = Math.Min(tableProperties.TableColumns, MAXIMUM_CELL_COL);
this.numericCellPadding.Value = Math.Min(tableProperties.CellPadding, MAXIMUM_CELL_PAD);
this.numericCellSpacing.Value = Math.Min(tableProperties.CellSpacing, MAXIMUM_CELL_PAD);
this.radioWidthPercent.Checked = (tableProperties.TableWidthMeasurement == MeasurementOption.Percent);
this.radioWidthPixel.Checked = (tableProperties.TableWidthMeasurement == MeasurementOption.Pixel);
this.numericTableWidth.Value = Math.Min(tableProperties.TableWidth, this.numericTableWidth.Maximum);
}
} //TableProperties
// define the measurement values based on the selected mesaurment selected
private void MeasurementOptionChanged(object sender, System.EventArgs e)
{
// define a dialog for a percentage change
if (this.radioWidthPercent.Checked)
{
this.numericTableWidth.Maximum = MAXIMUM_WIDTH_PERCENT;
this.numericTableWidth.Increment = MAXIMUM_WIDTH_PERCENT / WIDTH_INC_DIV;
}
// define a dialog for a pixel change
if (this.radioWidthPixel.Checked)
{
this.numericTableWidth.Maximum = MAXIMUM_WIDTH_PIXEL;
this.numericTableWidth.Increment = MAXIMUM_WIDTH_PIXEL / WIDTH_INC_DIV;
}
} //MeasurementOptionChanged
// Clean up any resources being used.
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} //Dispose
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TablePropertyForm));
this.bCancel = new System.Windows.Forms.Button();
this.bInsert = new System.Windows.Forms.Button();
this.groupCaption = new System.Windows.Forms.GroupBox();
this.listCaptionLocation = new System.Windows.Forms.ComboBox();
this.labelLocation = new System.Windows.Forms.Label();
this.listCaptionAlignment = new System.Windows.Forms.ComboBox();
this.labelCaptionAlign = new System.Windows.Forms.Label();
this.labelCaption = new System.Windows.Forms.Label();
this.textTableCaption = new System.Windows.Forms.TextBox();
this.groupLayout = new System.Windows.Forms.GroupBox();
this.numericCellSpacing = new System.Windows.Forms.NumericUpDown();
this.labelSpacing = new System.Windows.Forms.Label();
this.numericCellPadding = new System.Windows.Forms.NumericUpDown();
this.labelPadding = new System.Windows.Forms.Label();
this.numericColumns = new System.Windows.Forms.NumericUpDown();
this.numericRows = new System.Windows.Forms.NumericUpDown();
this.labelRowColumn = new System.Windows.Forms.Label();
this.groupPercentPixel = new System.Windows.Forms.Panel();
this.radioWidthPixel = new System.Windows.Forms.RadioButton();
this.radioWidthPercent = new System.Windows.Forms.RadioButton();
this.numericTableWidth = new System.Windows.Forms.NumericUpDown();
this.labelWidth = new System.Windows.Forms.Label();
this.groupTable = new System.Windows.Forms.GroupBox();
this.listTextAlignment = new System.Windows.Forms.ComboBox();
this.labelBorderAlign = new System.Windows.Forms.Label();
this.labelBorderSize = new System.Windows.Forms.Label();
this.numericBorderSize = new System.Windows.Forms.NumericUpDown();
this.groupCaption.SuspendLayout();
this.groupLayout.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericCellSpacing)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericCellPadding)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericColumns)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericRows)).BeginInit();
this.groupPercentPixel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericTableWidth)).BeginInit();
this.groupTable.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericBorderSize)).BeginInit();
this.SuspendLayout();
//
// bCancel
//
this.bCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.bCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.bCancel.Location = new System.Drawing.Point(320, 304);
this.bCancel.Name = "bCancel";
this.bCancel.TabIndex = 0;
this.bCancel.Text = "Cancel";
//
// bInsert
//
this.bInsert.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.bInsert.DialogResult = System.Windows.Forms.DialogResult.OK;
this.bInsert.Location = new System.Drawing.Point(240, 304);
this.bInsert.Name = "bInsert";
this.bInsert.TabIndex = 1;
this.bInsert.Text = "Insert";
//
// groupCaption
//
this.groupCaption.Controls.Add(this.listCaptionLocation);
this.groupCaption.Controls.Add(this.labelLocation);
this.groupCaption.Controls.Add(this.listCaptionAlignment);
this.groupCaption.Controls.Add(this.labelCaptionAlign);
this.groupCaption.Controls.Add(this.labelCaption);
this.groupCaption.Controls.Add(this.textTableCaption);
this.groupCaption.Location = new System.Drawing.Point(8, 8);
this.groupCaption.Name = "groupCaption";
this.groupCaption.Size = new System.Drawing.Size(384, 88);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?