Advertisement

03.23.2008 at 10:20PM PDT, ID: 23263461
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

print dialog apperas two times

Asked by ddipro in Microsoft Visual C#.Net

Tags: , ,

Hello Friends,
I am developing an application where i need to take print.
every thing is working good except that printdialog appears two times.

CODE
PrintDocument printDocument1 = new PrintDocument();

AT FORM LOAD
this.printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);

void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            try
            {
                e.Graphics.DrawImage(memoryImage, 0, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Function:

        private delegate void PrintBarcodeDeligate(object state);
        public void PrintBarcode(object state)
        {
            try
            {
                if (tableLayoutPanel1.InvokeRequired)
                {
                    tableLayoutPanel1.Invoke(new PrintBarcodeDeligate(PrintBarcode), new object[] { state }); // Invoke the called method through Message-Loop
                }
                else
                {
                    if (TextBoxBarcode.Text.Trim() == "" && listBoxtextfile.Items.Count < 1)
                    {
                        MessageBox.Show("Sorry there is no barcode to print.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        PrintDialog myPrintDialog = new PrintDialog();
                        if (TextBoxBarcode.Text.Trim().Length < 3 && listBoxtextfile.Items.Count < 1)
                        {
                            MessageBox.Show("Barcode length should be minimum 3 characters.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            if (listBoxtextfile.Items.Count < 1)
                            {
                                int count = Application.OpenForms.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    memoryImage = new System.Drawing.Bitmap(panel1.Width, panel1.Height);
                                    panel1.DrawToBitmap(memoryImage, panel1.ClientRectangle);
                                    if (myPrintDialog.ShowDialog() == DialogResult.OK)
                                    {
                                        myPrintDialog.Document = printDocument1;
                                        printDocument1.PrintController = new StandardPrintController();
                                        printDocument1.Print();
                                    }
                                    printDocument1.Dispose();
                                }
                            }
                            else
                            {
                                //PrintDialog myPrintDialog = new PrintDialog();
                                int count = Application.OpenForms.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (myPrintDialog.ShowDialog() == DialogResult.OK)
                                    {
                                        for (int k = 0; k <= listBoxtextfile.Items.Count - 1; k++)
                                        {
                                            labelBarcode.Text = "*" + listBoxtextfile.Items[k].ToString() + "*";
                                            labelBarcodeTxt.Text = "DEMO VERSION";//listBoxtextfile.Items[k].ToString();
                                            memoryImage = new System.Drawing.Bitmap(panel1.Width, panel1.Height);
                                            panel1.DrawToBitmap(memoryImage, panel1.ClientRectangle);
                                            myPrintDialog.Document = printDocument1;
                                            printDocument1.PrintController = new StandardPrintController();
                                            printDocument1.Print();
                                        }
                                    }
                                    printDocument1.Dispose();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            { }
        }
     
AT Button CLick
try
            {
                Thread tPrintBarcode = new Thread(PrintBarcode);
                tPrintBarcode.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }


Please help me.Start Free Trial
[+][-]03.24.2008 at 07:52AM PDT, ID: 21193881

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.31.2008 at 11:42PM PDT, ID: 21251686

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual C#.Net
Tags: Microsoft, C#.NET, 2.0
Sign Up Now!
Solution Provided By: ddipro
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628