• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

create application to print on a custom form

I want to create an application that prints data on a custom form. Any ideas how to go about it.The application will be printing addresses in a particular box on the form.

Thanks,
0
patd1
Asked:
patd1
  • 4
  • 2
  • 2
2 Solutions
 
dj_alikCommented:
Very simple solution in Winform is PrintForm Component
Printing the Form
http://msdn.microsoft.com/en-us/library/aa287529(v=vs.71).aspx
0
 
dj_alikCommented:
0
 
patd1Author Commented:
Thanks, but I need a c# application, so that I can understand and modify.
I already have printed requisition forms, this application will print the client address in a particular box on this form. If there is a c# class that I can use to print text on the x,y coordinates, that will be fine.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
anarki_jimbelCommented:
Wouldn't it be easier to put, say, a text box on your form and print your text t address there?
Otherwise you may end up writing all the logic required to place your text inside some boundaries, e.g.?
0
 
anarki_jimbelCommented:
I have written a class to draw on a form. I suppose I HAVE this place vacant on the form.

Currently the class does not care about text boundaries but has some properties to set them. It also has properties to set font, Color, start position etc. I'm just trying to give an idea.

I also have a form class with three buttons. Buttons 1 and 2 print some text on a form in the left upper corner. Button 3 wipes the text.

Try it!
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace blabla
{
    /// <summary>
    /// The class is intended to accept a form and print some text inside some boundaries
    /// </summary>
    public class OnFormPrinter
    {
        private int _PrintBoxHeight;
        private int _PrintBoxWidth;
        private System.Drawing.Font _FontToUse;
        private Color _TextColor;
        private PointF _PointToStartText;


        public PointF PointToStartText
        {
            get { return _PointToStartText; }
            set { _PointToStartText = value; }
        }

        public Color TextColor
        {
            get { return _TextColor; }
            set { _TextColor = value; }
        }

        public System.Drawing.Font FontToUse
        {
            get { return _FontToUse; }
            set { _FontToUse = value; }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        public OnFormPrinter()
        {
            // prepare default font etc
            _FontToUse = new System.Drawing.Font("Courier", 10);
            _TextColor = Color.Red;
            _PointToStartText = new PointF(10f, 10f);
        }

        public int PrintBoxHeight
        {
            get { return _PrintBoxHeight; }
            set { _PrintBoxHeight = value; }
        }


        public int PrintBoxWidth
        {
            get { return _PrintBoxWidth; }
            set { _PrintBoxWidth = value; }
        }



        public void PrintOnForm(System.Windows.Forms.Form formToPrintOn, string textToPrint)
        {
            Graphics g = formToPrintOn.CreateGraphics();
            g.DrawString(textToPrint, this.FontToUse, new SolidBrush(this.TextColor), this.PointToStartText);
        }

        public void ClearText(System.Windows.Forms.Form formToPrintOn)
        {
            Graphics g = formToPrintOn.CreateGraphics();
            g.Clear(formToPrintOn.BackColor);
        }


    }
}
====================================

// Form code to test the class above:

        OnFormPrinter pr = new OnFormPrinter();
        private void button1_Click(object sender, EventArgs e)
        {
            pr.PrintOnForm(this, "Hello");
        }
        private void button2_Click(object sender, EventArgs e)
        {
            pr.TextColor = Color.Green;
            pr.PrintOnForm(this, "Wiskey");
        }
        private void button3_Click(object sender, EventArgs e)
        {
            pr.ClearText(this);
        }

Open in new window

0
 
patd1Author Commented:
Thanks anarki_jimbel, I see that this class can be useful. I can position all my text on a from and then send it to the printer. Can you also please guide me on how to send this form to the printer.

Thank you.
0
 
patd1Author Commented:
Found an excellent solution at http://vbcity.com/forums/t/163513.aspx
0
 
patd1Author Commented:
This completes the solution.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now