|
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace FormPrintComponent
{
/// <summary>
/// A collection of print settings for all the controls on a form, for example
/// </summary>
public class ControlPrintSettings: Dictionary<Control, ControlPrintSetting >
{
#region private members
private System.Drawing.Printing.PaperKind _PaperKind ;
private uint _LogicalPageCount = 1;
#endregion
/// <summary>
/// The number of logical pages that this control print settings
/// collection is being printed for
/// </summary>
/// <remarks >
/// A logical page is like a template from which one or more physical
/// pages will be printed depending on how much data
/// </remarks>
public uint LogicalPageCount
{
get
{
return _LogicalPageCount;
}
set
{
_LogicalPageCount = value;
foreach (ControlPrintSetting cpl in this.Values )
{
cpl.LogicalPageCount = _LogicalPageCount;
}
}
}
/// <summary>
/// Collection indexer
/// </summary>
/// <param name="indexer">
/// The control to get the print setting(s) for
/// </param>
/// <returns>
/// </returns>
public new ControlPrintSetting this[Control indexer]
{
get
{
// If this control is not already in the collection, add it
if (! base.ContainsKey(indexer ))
{
if ( indexer is RichTextBox)
{
this.Add(indexer , new RTFControlPrintSetting((RichTextBox)indexer));
}
else
{
if (indexer is TextBox )
{
this.Add(indexer , new TextboxControlPrintSetting((TextBox)indexer));
}
else
{
this.Add(indexer , new ControlPrintSetting(indexer));
}
}
}
return base[indexer];
}
set { base[indexer] = value; }
}
/// <summary>
/// Returns a collection of controls that should be printed on this
/// logical page number
/// </summary>
/// <param name="LogicalpageNumber">
/// The logical page number to print
/// </param>
/// <returns>
/// </returns>
public List<ControlPrintSetting> ControlsToPrintForLogicalPage(int LogicalpageNumber)
{
List<ControlPrintSetting> _ret = new List<ControlPrintSetting>();
foreach (ControlPrintSetting cpl in this.Values )
{
switch (cpl.MultiPagePrintMethod)
{
case ControlPrintSetting.MultiPagePrintMethods.PrintOnEveryPage:
{
_ret.Add(cpl);
break;
}
case ControlPrintSetting.MultiPagePrintMethods.PrintOnOddPages:
{
if (LogicalpageNumber % 2 == 1)
{
_ret.Add(cpl);
}
break;
}
case ControlPrintSetting.MultiPagePrintMethods.PrintOnEvenPages:
{
if (LogicalpageNumber % 2 == 0)
{
_ret.Add(cpl);
}
break;
}
case ControlPrintSetting.MultiPagePrintMethods.PrintOnlyOnSpecifiedLogicalPages:
{
if (cpl.PrintOnPages[LogicalpageNumber-1])
{
_ret.Add(cpl);
}
break;
}
}
}
return _ret;
}
}
}
|
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.