UserPaint

Basic

UserPaint is a element for displaying external, user generated classes that extend Stampa.UserPaint class.

UserPaint class is a base class for user classes that contain the ability to paint themselves in a ReportDocument, One may consider UserPaint class as a mechanism to extend Stampa Reports functionallity to display user-defined objects.

In order to use this mechanism, users should create their own class that extends the Stampa.UserPaint class and implement Paint(Graphics g, Rectangle drawingArea) and Clone() methods. To achieve this, don't forget to reference Stampa.dll assembly in your project !

Example:

  public class MyPaint : Stampa.UserPaint
  {
	public MyPaint()
        {

	}

	public override void Paint(Graphics g, Rectangle drawingArea)
        {

           // it is a good practice to paint the background of your display element
           g.FillRectangle(Brushes.Yellow, drawingArea);
           // display some dummy string
           g.drawString("My text", Brushes.Black, new Font("Tahoma", 8), drawingArea);
        }

        public override object Clone()
        {
           // create deep copy of your element instance
           return new MyPaint();
	}
  }

In order to display this class, create a named instance of UserPaint element in your report (say, with the name "myUserPaint"). After setting xml template in your code, you should pass an instance of your class to the Report instace using method ReportDocument.AddUserPaint(string userPaintName, UserPaint userPaintInstance) :

  Stampa.ReportDocument printDocument = new Stampa.ReportDocument();

  printDocument.setXML("userPaintExample.xml");

  // create your class instance
  MyPaint m = new MyPaint();

  // pass this instance to the report object
  printDocument.AddUserPaint("myUserPaint", m);

  // ready to print
  printDocument.Print();

XML structure

Sample XML structure for UserPaint :

<userPaint x="101" y="374" width="150" height="100" horAlignment="None" verAlignment="None" 
    Layout="EveryPage" Selectable="True">
</userPaint>

Properties

Height UserPaint area rectangle height (in pixels).
HorizontalAlignment UserPaint alignment within page, relative to margins. Default value : None
Layout This property defines if element is displayed on every section page, first or last page only. Valid values are : EveryPage, FirstPage, LastPage. Default value : EveryPage
Selectable This property defines whether object can be selected by left mouse click in design mode. Useful for locking background objects during design mode. If set to false, object can only be selected through Object Browser. Default value : true
VerticalAlignment UserPaint vertical alignment within page, relative to margins. Default value : None
Width UserPaint area width (in pixels).
X Left border coordinate (in pixels).
Y Top border coordinate (in pixels).