Total members 11890 |It is currently Sat Apr 20, 2024 5:57 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






 Project Name:   HTML Table Of Contents Generator
 Programmer:   Andrew Peace
 Type:   Application
 Technology:  C#
 IDE:   NONE
 Description:   The aim of this program is to provide an easy method to produce a table of contents in a HTML file, which can be used to navigate through the article. When thinking over the problem, I realised that the program needed to be fairly simple but adaptable so that different styles of contents page can be generated. This may be important because whilst bulleted lists may be appropriate in one style, they may not be in another. Also, the user may wish to provide their own tags to change fonts etc. for the items in the contents listing. In addition to this, any proprietary text (i.e. text that is not taken from the article) should be customisable. This is mainly for the purpose of localisation - the World Wide Web is a global community and thus should be adaptable to fit the needs of more than one culture and language.
Code sample : fContentBuilder.cs
csharp code
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, 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);
}
}
}


Attachment:
htmlcb_main.gif
htmlcb_main.gif [ 9.09 KiB | Viewed 5069 times ]





Attachments:
htmlcb_exe.zip [8.74 KiB]
Downloaded 979 times
htmlcb_src.zip [15.63 KiB]
Downloaded 903 times

_________________
Please recommend my post if you found it helpful. ,
java,j2ee,ccna ,ccnp certified .
Author:
Expert
User avatar Posts: 838
Have thanks: 2 time

updated.


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : HTML Table Of Contents Generator
 JPA entity with table generator     -  
 database contents display in table format in swing     -  
 HTML Scrollable table     -  
 Sort HTML table from JQuery     -  
 adding caption to table in html     -  
 Use for loop to output HTML table     -  
 get the Contents of a ZIP File in java     -  
 Listing the Contents of a Directory     -  
 Calendar Generator     -  
 Sequence Generator JPA     -  



Topic Tags

C# Projects
cron






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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