UB-04 Form – Adding A Custom Field

Index

    Adding A Custom Field

    By default, the following fields are available; TextField, PriceField, PhoneField and UB04Date.

    Custom fields can be created easily. Just derive from the FormField class and override the GetText() method.

    Example

    public class MyCustomField : FormField
    {
       public MyCustomField(string name): base(name){}
       
       public MyCustomField(string name, decimal? data, double x, doubley, double width, double height): base(name, x, y, width, height){
           this.Data = data;
       }
     
       public MyCustomField(string name, decimal? data, double x, doubley, double width, double height, StringAlignment ha): base(name, x, y, width, height, ha){
           this.Data = data;
       }
     
       public MyCustomField(string name, decimal? data, double x, doubley, double width, double height, StringAlignment ha, StringAlignmentva): base(name, x, y, width, height,ha, va){
           this.Data = data;
       }
     
       public decimal? Data {
           get;
           set;
       }
     
       public override string GetText(){
           if (Data != null && Data.HasValue){
               return Data.Value.ToString(“F2”);
           }
           return null;
         }
    }
     
    To add your custom field to UB04Form just add it to the Cells collection when the BeforePrint event is raised.
     
    void ub04Form_BeforePrint(object sender, FormEventArgs e) {
     
      MyCustomField customField = new MyCustomField (“myID”, 112.22, 1, 1, 4, 1);
      //e.Cells has all fields that will e send to printer.
      e.Cells.Add(customField );
     
    }
    in UB – 04 Form
    Did this article answer your question?