Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Printanje kontrola u C#

[es] :: .NET :: .NET Desktop razvoj :: Printanje kontrola u C#

[ Pregleda: 2788 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

NeznamTkoSam

Član broj: 39660
Poruke: 279
*.cmu.carnet.hr.



Profil

icon Printanje kontrola u C#21.11.2004. u 15:31 - pre 236 meseci
Kako mogu isprintati neku formu ili button ili rich text box ili neku drugu kontrolu u C#?
 
Odgovor na temu

Mrav
Aleksandar Mraović
.net programer u Wireless Media
Beograd

Član broj: 6532
Poruke: 279
*.smin.sezampro.yu.

ICQ: 197419540


Profil

icon Re: Printanje kontrola u C#24.11.2004. u 00:20 - pre 236 meseci
Pretpostavljam da bi mogao da baciš sadržaj Graphics objekta kontrole (ili kako već možeš da izvučeš njen sadržaj) na Graphics PrintDocument-a kada štampaš.

Ako budem imao vremena pokušaću ovo pa ću da postujem nešto konkretnije.
Lepota je u jednostavnosti.

Cis.
 
Odgovor na temu

Mrav
Aleksandar Mraović
.net programer u Wireless Media
Beograd

Član broj: 6532
Poruke: 279
*.smin.sezampro.yu.

ICQ: 197419540


Profil

icon Re: Printanje kontrola u C#24.11.2004. u 03:21 - pre 236 meseci
Šta mi bi noćas nisam normalan

Code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Reflection;


namespace StampanjeFormi
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class PrintForm : System.Windows.Forms.Form
    {
        private System.Drawing.Printing.PrintDocument printDocument1;
        private System.Windows.Forms.Button dugme1;
        private System.Windows.Forms.Button dugme2;
        private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;
        private Image slika;

        public PrintForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PrintForm));
            this.dugme1 = new System.Windows.Forms.Button();
            this.dugme2 = new System.Windows.Forms.Button();
            this.printDocument1 = new System.Drawing.Printing.PrintDocument();
            this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
            this.SuspendLayout();
            // 
            // dugme1
            // 
            this.dugme1.Location = new System.Drawing.Point(32, 80);
            this.dugme1.Name = "dugme1";
            this.dugme1.Size = new System.Drawing.Size(104, 23);
            this.dugme1.TabIndex = 0;
            this.dugme1.Text = "PritisniZaStampu";
            this.dugme1.Click += new System.EventHandler(this.dugme1_Click);
            // 
            // dugme2
            // 
            this.dugme2.Location = new System.Drawing.Point(168, 80);
            this.dugme2.Name = "dugme2";
            this.dugme2.Size = new System.Drawing.Size(88, 23);
            this.dugme2.TabIndex = 1;
            this.dugme2.Text = "Stampam se!";
            this.dugme2.Paint += new System.Windows.Forms.PaintEventHandler(this.dugme2_Paint);
            // 
            // printDocument1
            // 
            this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
            // 
            // printPreviewDialog1
            // 
            this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
            this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
            this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
            this.printPreviewDialog1.Enabled = true;
            this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
            this.printPreviewDialog1.Location = new System.Drawing.Point(44, 44);
            this.printPreviewDialog1.MaximumSize = new System.Drawing.Size(0, 0);
            this.printPreviewDialog1.Name = "printPreviewDialog1";
            this.printPreviewDialog1.Opacity = 1;
            this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
            this.printPreviewDialog1.Visible = false;
            // 
            // PrintForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(328, 173);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.dugme2,
                                                                          this.dugme1});
            this.Name = "PrintForm";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new PrintForm());
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            
            MethodInfo invokepaintbackground = typeof(Control).GetMethod(
                "InvokePaintBackground",BindingFlags.Instance|BindingFlags.NonPublic);

            MethodInfo invokepaint = typeof(Control).GetMethod(
                "InvokePaint",BindingFlags.Instance|BindingFlags.NonPublic);
            slika = new Bitmap(dugme2.ClientRectangle.Width,dugme2.ClientRectangle.Height,PixelFormat.Format32bppArgb);
            Graphics temp = Graphics.FromImage(slika);
//
            PaintEventArgs pea = new PaintEventArgs(temp,dugme2.ClientRectangle);

            invokepaintbackground.Invoke(dugme2, new object[] { dugme2, pea });
            invokepaint.Invoke(dugme2, new object[] { dugme2, pea });

            Brush blend = new SolidBrush(Color.FromArgb(0,dugme2.Parent.BackColor));
            
            temp.FillRectangle(blend,dugme2.ClientRectangle);

        //    parentSurface.DrawImageUnscaled(bufferimage,c.Location.X,c.Location.Y);
            //
            e.Graphics.DrawImageUnscaled(slika,100,100,dugme2.ClientRectangle.Width,dugme2.ClientRectangle.Height);
            
            
            
            e.HasMorePages = false;
            
        }

        private void dugme1_Click(object sender, System.EventArgs e)
        {
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
        }

        private void dugme2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {

        }
    }
}


Nisam ni ja 100% siguran kako sam ovo uspeo, ali radi .Postoje još neki načini sa korišćenjem api funkcija, ali hteo sam to da izbegnem, ovo je najbolje što sam pronašao (pogledaj http://discuss.develop.com/arc...p;T=0&F=&S=&P=1141
to je rešenje koje sam prilagodio). Naime, imamo formu koja ima dva dugmeta, jedno poziva print preview a drugo je dugme koje se iscrtava na dokumentu, slično tome možeš proslediti bilo koju kontrolu da se iscrta, mogao bi da napišeš f-ju kojoj ćeš proslediti formu koju želiš da iscrtaš i recimo koordinate u dokumentu. Napomena je da to ne radi kako bi očekivao za neke složenije forme(kompozitne) gde bi morao da prođeš kroz kolekciju formi na toj formi da bi sve iscrtao.

P.S. kod je malo nakaradan i sigurno da mnogo toga možeš da središ, a i bolje od mene da razumeš šta sam ja to uopšte napisao
Lepota je u jednostavnosti.

Cis.
 
Odgovor na temu

NeznamTkoSam

Član broj: 39660
Poruke: 279
*.cmu.carnet.hr.



Profil

icon Re: Printanje kontrola u C#29.11.2004. u 21:49 - pre 236 meseci
TO TE JA PITAM!
thnx!
 
Odgovor na temu

[es] :: .NET :: .NET Desktop razvoj :: Printanje kontrola u C#

[ Pregleda: 2788 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.