Fri Nov 07, 2008 1:22 pm
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace ContentsMaker
{
/// <summary>
/// Summary description for fContentsBuilder.
/// </summary>
public class fContentsBuilder : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnBuild;
private System.Windows.Forms.TreeView tvContents;
private System.Windows.Forms.Button btnOptions;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
/// <summary>
/// default constructor shouldn't be used.
/// </summary>
private fContentsBuilder()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Constructor used to initialise the tree.
/// </summary>
/// <param name="treeBegin"></param>
private HtmlHeading TreeBegin;
private HtmlContentsBuilder ContentsBuilder;
public fContentsBuilder(HtmlHeading treeBegin, HtmlContentsBuilder Builder)
{
InitializeComponent();
TreeBegin = treeBegin;
ContentsBuilder = Builder;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#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()
{
this.btnClose = new System.Windows.Forms.Button();
this.btnBuild = new System.Windows.Forms.Button();
this.btnOptions = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.tvContents = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// btnClose
//
this.btnClose.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Location = new System.Drawing.Point(288, 288);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 2;
this.btnClose.Text = "Close";
//
// btnBuild
//
this.btnBuild.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.btnBuild.Location = new System.Drawing.Point(208, 288);
this.btnBuild.Name = "btnBuild";
this.btnBuild.TabIndex = 3;
this.btnBuild.Text = "Build";
this.btnBuild.Click += new System.EventHandler(this.btnBuild_Click);
//
// btnOptions
//
this.btnOptions.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.btnOptions.Location = new System.Drawing.Point(8, 288);
this.btnOptions.Name = "btnOptions";
this.btnOptions.TabIndex = 5;
this.btnOptions.Text = "Options";
this.btnOptions.Click += new System.EventHandler(this.btnOptions_Click);
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.label1.Location = new System.Drawing.Point(8, ;
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(344, 16);
this.label1.TabIndex = 0;
this.label1.Text = "Contents:";
//
// label2
//
this.label2.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.label2.Location = new System.Drawing.Point(8, 264);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(352, 16);
this.label2.TabIndex = 1;
this.label2.Text = "Click \'Build\' to insert the contents information into the HTML file.";
//
// tvContents
//
this.tvContents.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.tvContents.ImageIndex = -1;
this.tvContents.Indent = 19;
this.tvContents.Location = new System.Drawing.Point(8, 24);
this.tvContents.Name = "tvContents";
this.tvContents.SelectedImageIndex = -1;
this.tvContents.Size = new System.Drawing.Size(352, 232);
this.tvContents.TabIndex = 4;
//
// fContentsBuilder
//
this.AcceptButton = this.btnBuild;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.btnClose;
this.ClientSize = new System.Drawing.Size(368, 317);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnOptions,
this.tvContents,
this.btnBuild,
this.btnClose,
this.label2,
this.label1});
this.Name = "fContentsBuilder";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Contents Builder";
this.Load += new System.EventHandler(this.OnLoad);
this.ResumeLayout(false);
}
#endregion
private void OnLoad(object sender, System.EventArgs e)
{
// build the tree:
if (TreeBegin == null)
throw new System.Exception("The tree reference was null and so the tree could not be processed");
tvContents.Nodes.Clear();
AddNodes(TreeBegin, null);
}
private void AddNodes(HtmlHeading start, TreeNode parent)
{
HtmlHeading current = start;
while (current != null)
{
TreeNode tn = new TreeNode(current.HeadingName);
if (parent != null)
parent.Nodes.Add(tn);
else
tvContents.Nodes.Add(tn);
AddNodes(current.FirstChild(), tn); // add child nodes
current = current.NextSibling();
}
}
private void btnBuild_Click(object sender, System.EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
private void btnOptions_Click(object sender, System.EventArgs e)
{
fOptions OptionsDlg = new fOptions(ContentsBuilder);
OptionsDlg.ShowDialog(this);
}
}
}
Sun Jan 20, 2013 9:21 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.