none
How to take print out

    Question

  • I am doing a project and I want to print a data in following manner, and in 4 column.

    The given field is in database. so plz reply urjent.........I need Help

     

    Name: xyz                         Name: xyz

    Address: adfadsf                Address: asdf

    Phone no:1234                   Phone no:13413

    Friday, March 26, 2010 3:25 PM

Answers

  • You can use PrintDocument class to print your data as you require

    http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx


    Gaurav Khanna
    • Marked as answer by SamAgain Wednesday, March 31, 2010 11:26 AM
    Friday, March 26, 2010 4:57 PM
  • You can use following code to retrieve data from database table and then use PrintDocument class

    Dim dap As New SqlClient.SqlDataAdapter("SELECT * FROM TABLENAME", "Connection String")
    Dim dt As New DataTable
    dap.Fill(dt)

    Gaurav Khanna
    • Marked as answer by SamAgain Wednesday, March 31, 2010 11:25 AM
    Saturday, March 27, 2010 11:18 AM
  • for that you have to use the Data Set to fetch the data in different labels:

    Example:

    DataSet

     

    ds = objbllManualscan.select_AllData();//select statement here

     

    if (ds != null && ds.Tables != null && ds.Tables[0].Rows.Count > 0)

    {

     

    labelName.Text= ds.Tables[0].Rows[0]["Name"];

    labelAddress.Text= ds.Tables[0].Rows[0]["Address"];

    etc.................

    }


    Varun Kumar
    • Proposed as answer by varun007 Monday, March 29, 2010 6:28 AM
    • Marked as answer by SamAgain Wednesday, March 31, 2010 11:26 AM
    Monday, March 29, 2010 6:28 AM

All replies

  • You can use PrintDocument class to print your data as you require

    http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx


    Gaurav Khanna
    • Marked as answer by SamAgain Wednesday, March 31, 2010 11:26 AM
    Friday, March 26, 2010 4:57 PM
  • simply do this in this way:

    [System.Runtime.InteropServices.DllImport("gdi32.dll")]

            public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);

            private Bitmap memoryImage;

            private void CaptureScreen()

            {            

                    Graphics mygraphics = pnlPrint.CreateGraphics();          \\pnlPrint is a Panel which contains all your labels  Name,Address etc

                    Size s = pnlPrint.Size;

                    memoryImage = new Bitmap(s.Width, s.Height, mygraphics);

                    Graphics memoryGraphics = Graphics.FromImage(memoryImage);

                    IntPtr dc1 = mygraphics.GetHdc();

                    IntPtr dc2 = memoryGraphics.GetHdc();

                    BitBlt(dc2, 0, 0, pnlPrint.ClientRectangle.Width, pnlPrint.ClientRectangle.Height, dc1, 0, 0, 13369376);

                    mygraphics.ReleaseHdc(dc1);

                    memoryGraphics.ReleaseHdc(dc2);

                }

     

     

    on Print Button click:

    private void btnPrint_Click(object sender, EventArgs e)

            {          

                    CaptureScreen();

                    System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();

                    PrintDialog1.AllowSomePages = true;

                    PrintDialog1.ShowHelp = true;

                    PrintDialog1.Document = printDocument1;

                    DialogResult result = PrintDialog1.ShowDialog();

                    if (result == DialogResult.OK)

                    {

                        printDocument1.Print();

                        //docToPrint.Print();

                    }

     

                }

     

    Regards,


    Varun Kumar
    Saturday, March 27, 2010 5:44 AM
  • simply do this in this way:

    [System.Runtime.InteropServices.DllImport("gdi32.dll")]

            public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);

            private Bitmap memoryImage;

            private void CaptureScreen()

            {            

                    Graphics mygraphics = pnlPrint.CreateGraphics();          \\pnlPrint is a Panel which contains all your labels  Name,Address etc

                    Size s = pnlPrint.Size;

                    memoryImage = new Bitmap(s.Width, s.Height, mygraphics);

                    Graphics memoryGraphics = Graphics.FromImage(memoryImage);

                    IntPtr dc1 = mygraphics.GetHdc();

                    IntPtr dc2 = memoryGraphics.GetHdc();

                    BitBlt(dc2, 0, 0, pnlPrint.ClientRectangle.Width, pnlPrint.ClientRectangle.Height, dc1, 0, 0, 13369376);

                    mygraphics.ReleaseHdc(dc1);

                    memoryGraphics.ReleaseHdc(dc2);

                }

     

     

    on Print Button click:

    private void btnPrint_Click(object sender, EventArgs e)

            {          

                    CaptureScreen();

                    System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();

                    PrintDialog1.AllowSomePages = true;

                    PrintDialog1.ShowHelp = true;

                    PrintDialog1.Document = printDocument1;

                    DialogResult result = PrintDialog1.ShowDialog();

                    if (result == DialogResult.OK)

                    {

                        printDocument1.Print();

                        //docToPrint.Print();

                    }

     

                }

     

    Regards,


    Varun Kumar
    • Proposed as answer by varun007 Saturday, March 27, 2010 5:45 AM
    Saturday, March 27, 2010 5:44 AM
  • Hey, I want to retrive the data from Database...

    And it must be in the 4 column......

    According to above manner....

    Saturday, March 27, 2010 10:16 AM
  • You can use following code to retrieve data from database table and then use PrintDocument class

    Dim dap As New SqlClient.SqlDataAdapter("SELECT * FROM TABLENAME", "Connection String")
    Dim dt As New DataTable
    dap.Fill(dt)

    Gaurav Khanna
    • Marked as answer by SamAgain Wednesday, March 31, 2010 11:25 AM
    Saturday, March 27, 2010 11:18 AM
  • for that you have to use the Data Set to fetch the data in different labels:

    Example:

    DataSet

     

    ds = objbllManualscan.select_AllData();//select statement here

     

    if (ds != null && ds.Tables != null && ds.Tables[0].Rows.Count > 0)

    {

     

    labelName.Text= ds.Tables[0].Rows[0]["Name"];

    labelAddress.Text= ds.Tables[0].Rows[0]["Address"];

    etc.................

    }


    Varun Kumar
    • Proposed as answer by varun007 Monday, March 29, 2010 6:28 AM
    • Marked as answer by SamAgain Wednesday, March 31, 2010 11:26 AM
    Monday, March 29, 2010 6:28 AM
  • but how in four column?
    Wednesday, March 31, 2010 5:09 PM