Précédent   Forum du club des développeurs et IT Pro > Dotnet > Développement Windows > Windows Forms
Windows Forms Forum d'entraide sur le développement Windows Forms & Applications Windows. Avant de poster -> Articles Windows Forms
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 04/12/2012, 16h39   #1
sbouilland
Invité de passage
 
Homme Stéphane Bouilland
Ingénieur Biomédical
Inscription : octobre 2012
Messages : 19
Détails du profil
Informations personnelles :
Nom : Homme Stéphane Bouilland
Localisation : France, Somme (Picardie)

Informations professionnelles :
Activité : Ingénieur Biomédical
Secteur : Santé

Informations forums :
Inscription : octobre 2012
Messages : 19
Points : 4
Points : 4
Par défaut Ajuster la taille à l'impression

Bonjour,

Mon programme doit permettre d'imprimer une copie d'écran d'un formulaire. Le code suivant fonctionne, mais la copie d'écran semble trop grande, du coup je n'ai qu'un morceau qui apparait dans l'aperçu avant impression (cf la piece jointe) et c'est pareil lors de l'impression.
Y'a t'il un paramètre qui permet d'ajuster automatiquement la taille du document à celle du papier ?
D'autre part, j'aimerai que la copie d'écran ne prenne que l'intérieur de la fenêtre, sans les menus et les barres d'outils, comment puis-je faire cela ?

Merci d'avance pour votre aide.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
private void MenuImprimer(object sender, EventArgs e)
        {
 
            PrintDocument printDocument1 = new PrintDocument();
            printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
 
            PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
            printDocument1.DefaultPageSettings.Landscape = true;
            printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("PaperA4", 826, 1169);
 
 
            printPreviewDialog1.Document = printDocument1;
 
            CaptureScreen();
            printPreviewDialog1.ShowDialog();
 
        }
 
        private void printDocument1_PrintPage(System.Object sender,System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 0, 0);
        }
 
        Bitmap memoryImage;
 
        private void CaptureScreen()
        {
            Graphics myGraphics = this.CreateGraphics();
            Size s = this.Size;
            memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
 
        }
    }
Images attachées
Type de fichier : jpg Sans titre-1.jpg (124,3 Ko, 1 affichages)
sbouilland est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/12/2012, 11h43   #2
sbouilland
Invité de passage
 
Homme Stéphane Bouilland
Ingénieur Biomédical
Inscription : octobre 2012
Messages : 19
Détails du profil
Informations personnelles :
Nom : Homme Stéphane Bouilland
Localisation : France, Somme (Picardie)

Informations professionnelles :
Activité : Ingénieur Biomédical
Secteur : Santé

Informations forums :
Inscription : octobre 2012
Messages : 19
Points : 4
Points : 4
Je crois que j'ai trouvé... ci-dessous le code corrigé.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
        private void MenuImprimer(object sender, EventArgs e)
        {
 
            PrintDocument printDocument1 = new PrintDocument();
            printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
 
            PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
            printDocument1.DefaultPageSettings.Landscape = true;
            printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("PaperA4", 826, 1169);
 
 
            printPreviewDialog1.Document = printDocument1;
         /*   printPreviewDialog1.PrintPreviewControl.AutoZoom = true;*/
            FormBorderStyle = FormBorderStyle.None;
            menuStrip1.Visible = false;
 
            Refresh();
            CaptureScreen();
            FormBorderStyle = FormBorderStyle.Sizable;
            menuStrip1.Visible = true;
            printPreviewDialog1.ShowDialog();
 
        }
 
        private void printDocument1_PrintPage(System.Object sender,System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 0, 0);
        }
 
        Bitmap memoryImage;
 
        private void CaptureScreen()
        {
            Graphics myGraphics = this.CreateGraphics();
            Size s = this.Size;
            memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            memoryImage.SetResolution(165, 165);
 
        /*    memoryImage = new Bitmap(memoryImage1, new Size(s.Width / 2, s.Height/2)); */
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
 
        }
    }
sbouilland est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 21h00.


 
 
 
 
Partenaires

Hébergement Web