Click here to Skip to main content
11,714,776 members (77,012 online)
Click here to Skip to main content
Add your own
alternative version

RTF Document Constructor Library

, 16 Aug 2010 CPOL 80.1K 2.9K 95
Create Rich Text Format documents programatically.
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace ESCommon.Rtf
{
    /// <summary>
    /// Represents a collection of columns in a ESCommon.Rtf.RtfTable
    /// </summary>
    public class RtfTableColumnCollection : ICollection<RtfTableColumn>, IEnumerable<RtfTableColumn>
    {
        private RtfTable Table;
        private List<RtfTableColumn> list;

        /// <summary>
        /// Gets ESCommon.Rtf.RtfTableColumn at specified location.
        /// </summary>
        /// <param name="index">A zero-based index of ESCommon.Rtf.RtfTableColumn to get.</param>
        public RtfTableColumn this[int index]
        {
            get { return list[index]; }
        }

        /// <summary>
        /// Gets the number of columns in the collection.
        /// </summary>
        public int Count
        {
            get { return list.Count; }
        }


        /// <summary>
        /// Initializes a new instance of ESCommon.Rtf.RtfTableColumnCollection class.
        /// </summary>
        /// <param name="table">Owning table.</param>
        internal RtfTableColumnCollection(RtfTable table)
        {
            list = new List<RtfTableColumn>();
            Table = table;
        }
        
        /// <summary>
        /// Adds a new ESCommon.Rtf.RtfTableColumn to the collection.
        /// </summary>
        public void Add()
        {
            Add(new RtfTableColumn());
        }

        /// <summary>
        /// Adds the specified ESCommon.Rtf.RtfTableColumn to the collection.
        /// </summary>
        public void Add(RtfTableColumn rtfTableColumn)
        {
            OnAddingColumn(rtfTableColumn);

            int num = list.Count;
                
            list.Add(rtfTableColumn);

            rtfTableColumn.IndexInternal = num;

            foreach (RtfTableRow row in Table.Rows)
            {
                if (row.Cells.Count > num)
                    row.Cells[num].ColumnInternal = rtfTableColumn;
            }
        }

        /// <summary>
        /// Adds the specified ESCommon.Rtf.RtfTableColumn objects to the collection.
        /// </summary>
        public void AddRange(RtfTableColumn[] rtfTableColumns)
        {
            foreach (RtfTableColumn column in rtfTableColumns)
            {
                if (column != null)
                    this.Add(column);
                else
                    this.Add(new RtfTableColumn());
            }
        }

        /// <summary>
        /// Determines if an element is in the collection.
        /// </summary>
        /// <param name="cell">An instance of ESCommon.Rtf.RtfTableColumn to locate in the collection.</param>
        public bool Contains(RtfTableColumn rtfTableColumn)
        {
            return list.Contains(rtfTableColumn);
        }

        /// <summary>
        /// Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array.
        /// </summary>
        /// <param name="array">The one-dimensional System.Array that is the destination of the elements.</param>
        /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
        public void CopyTo(RtfTableColumn[] array, int arrayIndex)
        {
            list.CopyTo(array, arrayIndex);
        }
        

        private void OnAddingColumn(RtfTableColumn rtfTableColumn)
        {
            if (rtfTableColumn == null)
                throw (new ArgumentNullException("RtfTableColumn cannot be null"));

            if (rtfTableColumn.TableInternal != null)
                throw (new InvalidOperationException("RtfTableColumn already belongs to a RtfTable"));

            rtfTableColumn.TableInternal = this.Table;
        }


        void ICollection<RtfTableColumn>.Clear()
        {
            
        }

        bool ICollection<RtfTableColumn>.IsReadOnly
        {
            get { return false; }
        }

        bool ICollection<RtfTableColumn>.Remove(RtfTableColumn item)
        {
            return false;
        }

        IEnumerator<RtfTableColumn> IEnumerable<RtfTableColumn>.GetEnumerator()
        {
            throw new NotImplementedException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dima Popov
Software Developer Energoservice
Russian Federation Russian Federation
Dmitry lives in Arkhangelsk, Russia. He has developed C# applications since 2007.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150819.1 | Last Updated 16 Aug 2010
Article Copyright 2010 by Dima Popov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid