C# Screenshots direkt per Email versenden

#3022860
Lesenswert?

Halllo Freunde ich würde gerne ein aufgenommen Screenshot auf Knopfdruck 
per Email versenden und hab als Anfänger keine Idee wie ich das angehen 
soll.

Ich erzeuge derzeit das Bild auf die folgende Art:
1
 private Image TabToImage(TabPage tabPage)
2
        {
3
            Bitmap bitmap = new Bitmap(tabPage.Width, tabPage.Height);
4
            Image image = bitmap;
5
            Graphics g = Graphics.FromImage(image);
6

7
            g.DrawImage(tabPage.BackgroundImage, 
8
                        new Rectangle(new Point(0, 0),
9
                                      tabPage.Size));
10

11
            foreach (Control control in tabPage.Controls)
12
            {
13
                if (control.GetType() == typeof(CheckBox))
14
                {
15
                    g.FillRectangle(new SolidBrush(control.BackColor),
16
                                    new Rectangle(control.Location.X,
17
                                                  control.Location.Y,
18
                                                  control.Width,
19
                                                  control.Height));
20
                    
21
                    g.DrawRectangle(new Pen(new SolidBrush(control.ForeColor)),
22
                                    new Rectangle(control.Location.X,
23
                                                  control.Location.Y,
24
                                                  control.Width,
25
                                                  control.Height));
26

27
                    if (((CheckBox)control).Checked)
28
                    {
29
                        g.DrawLine(new Pen(new SolidBrush(control.ForeColor)),
30
                                   new Point(control.Location.X + 2, control.Location.Y + 2),
31
                                   new Point(control.Location.X + control.Width - 2, control.Location.Y + control.Height - 2));
32
                        g.DrawLine(new Pen(new SolidBrush(control.ForeColor)),
33
                                   new Point(control.Location.X + control.Width - 2, control.Location.Y + 2),
34
                                   new Point(control.Location.X + 2, control.Location.Y + control.Height - 2));
35
                    }
36
                }
37
                else if (control.GetType() == typeof(TextBox) || control.GetType() == typeof(ComboBox))
38
                {
39
                    g.FillRectangle(new SolidBrush(control.BackColor),
40
                                  new Rectangle(control.Location.X,
41
                                                control.Location.Y,
42
                                                control.Width,
43
                                                control.Height));
44

45
                    g.DrawRectangle(new Pen(new SolidBrush(control.ForeColor)),
46
                                    new Rectangle(control.Location.X,
47
                                                  control.Location.Y,
48
                                                  control.Width,
49
                                                  control.Height));
50

51
                    g.DrawString(control.Text,
52
                                 control.Font,
53
                                 new SolidBrush(control.ForeColor),
54
                                 new PointF(control.Location.X + 2, control.Location.Y + 2));
55
                }
56
                else if (control.GetType() == typeof(Label))
57
                {
58
                    g.DrawString(control.Text,
59
                                 control.Font,
60
                                 new SolidBrush(control.ForeColor),
61
                                 new PointF(control.Location.X, control.Location.Y));
62
                }
63
            }
64

65
            g.Save();
66
            g.Dispose();
67
            return image;
68
        }
#3022895
Lesenswert?

1
   var bmp = new Bitmap(tabPage.Size.Width, tabPage.Size.Height);
2
   ...
3
   tabPage.DrawToBitmap(bmp, new Rectangle(0, 0, tabPage.Size.Width, tabPage.Size.Height)); 
4
   ...
Macht das etwas einfacher, wenn man mit den Einschränkungen leben kann. 
Siehe
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.drawtobitmap.aspx

Zum Versenden als Email wären die Stichwörter u.a.: MailMessage und 
SmtpClient
http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx
http://msdn.microsoft.com/en-us/library/vstudio/system.net.mail.smtpclient.aspx
#3025444
Lesenswert?

Markus Borti schrieb:
> Email verschickt man grundsätzlich mit den Klassen des
>
> System.Net.Mail-Namespaces..
>
>
>
> Da gibt es eine Klasse, die Attachement heißt.
>
> Da ist auch ein schöner Beispielcode drin.
>
> Wenn du dich daran hältst, sollte das eigentlich passend funktionieren.
>
>
>
> http://msdn.microsoft.com/de-de/library/system.net...

Klasse! Ich denke das war der wichtigste Punkt.
Aber das Dokument bzw. Bild muss zu diesem Zeitpunkt bereits existieren?

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren