Laden...

Screenshot von Windows Forms: Hintergrund ist da, die Labels fehlen

Erstellt von Drain vor 9 Jahren Letzter Beitrag vor 9 Jahren 1.357 Views
D
Drain Themenstarter:in
1 Beiträge seit 2014
vor 9 Jahren
Screenshot von Windows Forms: Hintergrund ist da, die Labels fehlen

Hallo Menschen,

Ich bin recht neu im C# Gebiet und habe ein Problem, ich möchte einen Screenshot von Form 3 machen, sobald diese gestartet wird. Soweit so gut, Screenshot wird gemacht, aber nur der Hintergrund ist da, die Labels fehlen aber 😒

Hier mein Code:


public Form3()
        {
            InitializeComponent();
            using (StreamReader sr1 = new StreamReader("c:\\Daten\\TEMP\\tempNR.txt"))
            {
                String Nr = sr1.ReadLine();
                lblNr1.Text = Nr;
                sr1.Close();
            }
            var b = new Bitmap(this.Width, this.Height);
            this.DrawToBitmap(b, new Rectangle(0, 0, this.Width, this.Height));

            Point p = this.PointToScreen(Point.Empty);

            Bitmap target = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
            using (Graphics g = Graphics.FromImage(target))
            {
                g.DrawImage(b, 0, 0,
                            new Rectangle(p.X - this.Location.X, p.Y - this.Location.Y,
                                          target.Width, target.Height),
                           GraphicsUnit.Pixel);
            }
            target.Save("C:\\Daten\\TEMP\\export.bmp");
            b.Dispose();
            using (var bmp = new Bitmap(this.Width, this.Height))
            {
                this.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
                bmp.Save(@"C:\\Daten\\TEMP\\export2.bmp");
            }

        
       
        }


Bitte kann jemand helfen? 😒

Lg
D.

3.170 Beiträge seit 2006
vor 9 Jahren

Hallo,

ist es nötig, dass das Fenster offscreen gerendert wird?
Wenn das Fenster zur Zeit des Screenshots auch angezeigt wird, geht es wesenlich einfacher mit Graphics.CopyFromScreen(...)

Gruß, MarsStein

Non quia difficilia sunt, non audemus, sed quia non audemus, difficilia sunt! - Seneca