我没有从活动表单中获得准确的打印: [英] I'm not getting exact print from the active form:

查看:46
本文介绍了我没有从活动表单中获得准确的打印:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的第二篇帖子抱歉,如果我错过任何主题或任何错误。



点击页面设置我可以使用控制但问题是,它在设置中向我展示了一些代码,并且在点击打印预览时它显示了一个空白页面,所以即使我正在尝试打印它也会给出一个空白页面。请帮助我解决这类问题或谁知道。



这是我的完整代码:



Hi, This is my second post sorry if i'm missing any threads or any mistake.

While clicking on page setup i'm able to use the controls but the problem is , it is showing me some code in the setup and while clicking on print preview it is displaying me a blank page so even when i'm trying to take a print it is giving a blank page. Please help me who came cross this type of problem or whoever knows.

Here is my complete code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Drawing.Printing;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Timers;

namespace ComplaintReport
{
    public partial class MRU240 : Form
    {

        private PrintPreviewDialog Pv;
        private PageSetupDialog Ps;
        private PrintDocument Pd;
        private PrintDialog Pr;

        private System.Windows.Forms.MainMenu mainMenu1;
        private System.Windows.Forms.MenuItem mnuFile;
        private System.Windows.Forms.MenuItem mnuSetup;
        private System.Windows.Forms.MenuItem mnuPreview;
        private System.Windows.Forms.MenuItem mnuPrint;
        private System.Windows.Forms.Button cmdQuit;

         public MRU240()
        {
            InitializeComponent();

            Pv = new PrintPreviewDialog();
            Ps = new PageSetupDialog();
            Pr = new PrintDialog();
            Pd = new PrintDocument();

            Pd.DocumentName = "My New Document";
            Pv.Document = Pd;
            Ps.Document = Pd;
            Pr.Document = Pd;
        }

       
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string cs = "Data Source=192.168.1.133;database=ComplaintReport;user id=sa;password=ssdrnd";
            SqlConnection conn = new SqlConnection(cs);
            SqlCommand cmd = new SqlCommand();
            conn.Open();
           
            SqlDataAdapter da = new SqlDataAdapter("select Mno from MRU240", conn);
            DataSet ds = new DataSet();
            cmd = new SqlCommand("select Mno from MRU240", conn);
            da.Fill(ds, "mru240");

            comboBox1.DataSource = ds.Tables["mru240"];
            comboBox1.DisplayMember = "Mno";
            conn.Close();
           
            
        }

      
        private void toolStripMenuback_Click(object sender, EventArgs e)
        {
            SSCVR obj6 = new SSCVR();
            obj6.Show();
            this.Hide();
        }
       

        private void MRU240_Load(object sender, EventArgs e)
        {
            comboBox1.DropDownHeight = comboBox1.ItemHeight * 10;
            comboBox1.MouseWheel += new MouseEventHandler(comboBox1_MouseWheel);
   
          

        }
        void comboBox1_MouseWheel(object sender, MouseEventArgs e)
        {
            ((HandledMouseEventArgs)e).Handled = true;
        }
        


        private void btnexit_Click(object sender, EventArgs e)
        {
            SSCVRGSE obj4 = new SSCVRGSE();
            obj4.Show();
            this.Hide();
        }



        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string cs = "Data Source=192.168.1.133;database=ComplaintReport;user id=sa;password=ssdrnd";
            SqlConnection conn = new SqlConnection(cs);
            if (txtsno.Text == "")
            {
                MessageBox.Show("Please enter serial number");
                txtsno.Focus();
            }
            if (txtsno.Text.Length >= 7)
            {
                MessageBox.Show("Serial number below 7 charachters ");
                txtsno.Focus();
            }


            try
            {
                string cfd = txt1.Text;
                string Uno = txt2.Text;
                string Mno = txtsno.Text;
                string cprc = txt3.Text;
                string sdc = txt4.Text;
                string contact = txt5.Text;
                string orderno = txt6.Text;
                string ino = txt7.Text;
                string consig = txt8.Text;
                string pft = txt9.Text;
                string remarks = txt11.Text;
                string obsv = txt12.Text;
                string disptach = txt13.Text;
                string repair = txt14.Text;
                string cause = txt15.Text;
                string userinfo = txt16.Text;
                string remedial = txt17.Text;
                string feedbck = txt18.Text;
                string conclu = txt19.Text;
                string notes = txt20.Text;
           
                SqlCommand cmd = new SqlCommand("insert into MRU240 values(@cfd,@Uno,@Mno,@cprc,@sdc,@contact,@orderno,@ino,@consig,@pft,@remarks,@obsv,@dispatch,@repair,@cause,@userinfo,@remedial,@feedbck,@conclu,@notes)", conn);
                cmd.Parameters.AddWithValue("@cfd", cfd);
                cmd.Parameters.AddWithValue("@Uno", Uno);
                cmd.Parameters.AddWithValue("@Mno", Mno);
                cmd.Parameters.AddWithValue("@cprc", cprc);
                cmd.Parameters.AddWithValue("@sdc", sdc);
                cmd.Parameters.AddWithValue("@contact", contact);
                cmd.Parameters.AddWithValue("@orderno", orderno);
                cmd.Parameters.AddWithValue("@ino", ino);
                cmd.Parameters.AddWithValue("@consig", consig);
                cmd.Parameters.AddWithValue("@pft", pft);
                cmd.Parameters.AddWithValue("@remarks", remarks);
                cmd.Parameters.AddWithValue("@obsv", obsv);
                cmd.Parameters.AddWithValue("@dispatch", disptach);
                cmd.Parameters.AddWithValue("@repair", repair);
                cmd.Parameters.AddWithValue("@cause", cause);
                cmd.Parameters.AddWithValue("@userinfo", userinfo);
                cmd.Parameters.AddWithValue("@remedial", remedial);
                cmd.Parameters.AddWithValue("@feedbck", feedbck);
                cmd.Parameters.AddWithValue("@conclu", conclu);
                cmd.Parameters.AddWithValue("@notes", notes);

                conn.Open();
                int i = cmd.ExecuteNonQuery();
                if (i == 1)
                {
                    MessageBox.Show("Record is saved ");
                    clearAll();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            conn.Close();

        }

        private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
           

            string cs = "server=192.168.1.133;database=ComplaintReport;user id=sa;password=ssdrnd";
            SqlConnection conn = new SqlConnection(cs);
            SqlCommand cmd = new SqlCommand();
            try
            {
                conn.Open();
                int dbsno = int.Parse(comboBox1.Text);

                cmd = new SqlCommand("select * from MRU240 where Mno=@dbsno", conn);
                cmd.Parameters.AddWithValue("@dbsno", dbsno);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    txt1.Text = dr["cfd"].ToString();
                    txt2.Text = dr["Uno"].ToString();
                    txtsno.Text = dr["Mno"].ToString();
                    txt3.Text = dr["cprc"].ToString();
                    txt4.Text = dr["sdc"].ToString();
                    txt5.Text = dr["contact"].ToString();
                    txt6.Text = dr["orderno"].ToString();
                    txt7.Text = dr["ino"].ToString();
                    txt8.Text = dr["consignee"].ToString();
                    txt9.Text = dr["pft"].ToString();
                    txt12.Text = dr["observation"].ToString();
                    txt13.Text = dr["dispatch"].ToString();
                    txt14.Text = dr["repair"].ToString();
                    txt15.Text = dr["cause"].ToString();
                    txt16.Text = dr["userinfo"].ToString();
                    txt17.Text = dr["remedial"].ToString();
                    txt18.Text = dr["feedback"].ToString();
                    txt19.Text = dr["conclusion"].ToString();
                    txt20.Text = dr["notes"].ToString();
                    txt11.Text = dr["remarks"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            conn.Close();
        }

        private void btnupdate_Click_1(object sender, EventArgs e)
        {
            string cs = "Data Source=192.168.1.133;database=ComplaintReport;user id=sa;password=ssdrnd";
            SqlConnection conn = new SqlConnection(cs);

            string cfd = txt1.Text;
            string Uno = txt2.Text;
            string Mno = txtsno.Text;
            string cprc = txt3.Text;
            string sdc = txt4.Text;
            string contact = txt5.Text;
            string orderno = txt6.Text;
            string ino = txt7.Text;
            string consig = txt8.Text;
            string pft = txt9.Text;
            string remarks = txt11.Text;
            string obsv = txt12.Text;
            string disptach = txt13.Text;
            string repair = txt14.Text;
            string cause = txt15.Text;
            string userinfo = txt16.Text;
            string remedial = txt17.Text;
            string feedbck = txt18.Text;
            string conclu = txt19.Text;
            string notes = txt20.Text;
            int dbsno = int.Parse(comboBox1.Text);
            SqlCommand cmd = new SqlCommand("update MRU240 set cfd=@cfd,Uno=@Uno,cprc=@cprc,sdc=@sdc,contact=@contact,orderno=@orderno,ino=@ino,consignee=@consig,pft=@pft,remarks=@remarks,observation=@obsv,dispatch=@dispatch,repair=@repair,cause=@cause,userinfo=@userinfo,remedial=@remedial,feedback=@feedbck,conclusion=@conclu,notes=@notes where Mno=@dbsno", conn);
            cmd.Parameters.AddWithValue("@cfd", cfd);
            cmd.Parameters.AddWithValue("@Uno", Uno);
            cmd.Parameters.AddWithValue("@Mno", Mno);
            cmd.Parameters.AddWithValue("@cprc", cprc);
            cmd.Parameters.AddWithValue("@sdc", sdc);
            cmd.Parameters.AddWithValue("@contact", contact);
            cmd.Parameters.AddWithValue("@orderno", orderno);
            cmd.Parameters.AddWithValue("@ino", ino);
            cmd.Parameters.AddWithValue("@consig", consig);
            cmd.Parameters.AddWithValue("@pft", pft);
            cmd.Parameters.AddWithValue("@remarks", remarks);
            cmd.Parameters.AddWithValue("@obsv", obsv);
            cmd.Parameters.AddWithValue("@dispatch", disptach);
            cmd.Parameters.AddWithValue("@repair", repair);
            cmd.Parameters.AddWithValue("@cause", cause);
            cmd.Parameters.AddWithValue("@userinfo", userinfo);
            cmd.Parameters.AddWithValue("@remedial", remedial);
            cmd.Parameters.AddWithValue("@feedbck", feedbck);
            cmd.Parameters.AddWithValue("@conclu", conclu);
            cmd.Parameters.AddWithValue("@notes", notes);
            cmd.Parameters.AddWithValue("@dbsno", dbsno);
          
            conn.Open();
            int i = (int)cmd.ExecuteNonQuery();
            if (i >= 1)
            {
                MessageBox.Show("Record is updated ");
                clearAll();
                txt2.Text = "";
            }
            else
            {
                MessageBox.Show("Record is not updated");
            }
            conn.Close();
        }
       

        private void txtsno_Leave(object sender, EventArgs e)
        {
            if (txtsno.Text == "")
            {
                MessageBox.Show("Please enter serial number");
                txtsno.Focus();
            }
            if (txtsno.Text.Length >= 7)
            {
                MessageBox.Show("Enter below 7 charachers ");
                txtsno.Focus();
            }

        }

        protected override void OnPaint(PaintEventArgs e)
        {
            DrawIt(e.Graphics);
        }

        private void DrawIt(Graphics G)
        {
            //PrintDocument document = new PrintDocument();
            //document.PrintPage += new PrintPageEventHandler(document_PrintPage);
            CaptureScreen();

        }
        private Bitmap _memoryImage;



        private void CaptureScreen()
        {
            // put into using construct because Graphics objects do not 
            //  get automatically disposed when leaving method scope
            using (var myGraphics = CreateGraphics())
            {
                var s = Size;
                _memoryImage = new Bitmap(1500, 1000, myGraphics);
                using (var memoryGraphics = Graphics.FromImage(_memoryImage))
                {
                    printDocument2.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("PaperA4", 826, 1169);
                    memoryGraphics.CopyFromScreen(Location.X, Location.Y, 70, 30, s);
                }
            }
        }
        private void printDocument2_PrintPage(object sender, PrintPageEventArgs e)
        {
            // calculate width and height scalings taking page margins into account
            var wScale = e.MarginBounds.Width / (float)_memoryImage.Width;
            var hScale = e.MarginBounds.Height / (float)_memoryImage.Height;

            // choose the smaller of the two scales
            var scale = wScale < hScale ? wScale : hScale;

            // apply scaling to the image
            e.Graphics.ScaleTransform(scale, scale);

            // print to default printer's page
            e.Graphics.DrawImage(_memoryImage, 70, 30);
            printDocument2.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("PaperA4", 826, 1169);
        }


        private void pd_Print(object sender, PrintPageEventArgs e)
        {
            DrawIt(e.Graphics);
        }


        private void pageSetupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Ps.ShowDialog();
            Pd.DefaultPageSettings = Ps.PageSettings;
            Pd.PrinterSettings = Ps.PrinterSettings;
        }

        private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Pv.WindowState = FormWindowState.Maximized;
            Pv.ShowDialog();
        }

        private void printToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Pr.ShowDialog() == DialogResult.OK)
                Pd.Print();
        }
    }
}

推荐答案

这篇关于我没有从活动表单中获得准确的打印:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆