CS-Script 3.27.0

Printing (importing script)   

Step-by-step tutorial 

The following tutorial shows how to create and execute the script that allows users to print any text string to the default printer with print preview. This is an example of multiple scripts application. 

  1. By using any text editor (eg. Notepad.exe) create file printText.cs, which contains the following code:
    //css_import print;
    using
     System;
    using System.Text;
    using Scripting;

    class Script
    {
        static public void Main(string[] args)
        {
            if (args.Length != 0)       
            {
                SimplePrinting printer = new SimplePrinting();
                printer.Print(args[0], true);
            }
        }
    }

    Click here to obtain full listing of PrintText.cs 
  2. Open command prompt. Make sure current directory is the directory where printText.cs located. 
  3. Execute the following command in command-prompt:
    cscs printText "Printing from script..."

Output 

The script will show the following dialog.  

Now you start printing by pressing 'print' button.

Code discussion 

You probably noticed special directive //css_import print; just before class declaration. This directive instructs the script engine to load at runtime another script ('print.cs'). This script is located in cs-script/Lib, however the same result would be achieved if it was in the same directory with PrintText.cs. Print.cs script contains implementation of SimplePrinting class which belongs to namespace Scripting (this is why "using Scripting;" was placed in the code). The usage of the class SimplePrinting is the same as if it was implemented in the main script file (PrintText.cs).  

See Also

CS-Script tutorials | Importing scripts