Click here to Skip to main content
15,881,715 members
Home / Discussions / C#
   

C#

 
AnswerRe: Why does NullReferenceException throw irrelevantly? I already tried - no success. Pin
Gerry Schmitz22-Dec-20 3:33
mveGerry Schmitz22-Dec-20 3:33 
SuggestionSQLLight vs SQL CE Pin
Alex Dunlop20-Dec-20 8:16
Alex Dunlop20-Dec-20 8:16 
GeneralRe: SQLLight vs SQL CE Pin
Gerry Schmitz20-Dec-20 9:19
mveGerry Schmitz20-Dec-20 9:19 
GeneralRe: SQLLight vs SQL CE Pin
Mycroft Holmes20-Dec-20 11:15
professionalMycroft Holmes20-Dec-20 11:15 
QuestionHow to save panel content into PDF Pin
RedPandinus19-Dec-20 17:46
RedPandinus19-Dec-20 17:46 
AnswerRe: How to save panel content into PDF Pin
OriginalGriff19-Dec-20 19:57
mveOriginalGriff19-Dec-20 19:57 
SuggestionRe: How to save panel content into PDF Pin
RedPandinus19-Dec-20 20:30
RedPandinus19-Dec-20 20:30 
GeneralRe: How to save panel content into PDF Pin
OriginalGriff19-Dec-20 22:57
mveOriginalGriff19-Dec-20 22:57 
First off, you are creating objects which use significantly scarce resources, and so require Disposal or you app will crash with "out of memory" errors pretty quickly.
You are responsible for all Graphics objects you create, and all Images - and the Garbage collector will not get called in to dispose of them if you run out of handles for example.

Reworking your code to do that:
C#
using (Image bmp = new Bitmap(panel1.Width, panel1.Height))
    {
    using (Graphics gg = Graphics.FromImage(bmp))
        {
        Rectangle rect = panel1.RectangleToScreen(panel1.ClientRectangle);
        gg.CopyFromScreen(rect.Location, Point.Empty, panel1.Size);
        bmp.Save(@"D:\Temp\AAATest.jpg", ImageFormat.Jpeg);
        using (Graphics g = panel1.CreateGraphics())
            {
            g.Clear(Color.White);
            }
        }
    }
And trying it gives me the panel itself, the whole panel, and no other image content.

So what am I doing that you aren't?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!

GeneralRe: How to save panel content into PDF Pin
RedPandinus20-Dec-20 6:07
RedPandinus20-Dec-20 6:07 
GeneralAForge Motion Detection from PictureBox? Pin
Herboren19-Dec-20 17:15
Herboren19-Dec-20 17:15 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz19-Dec-20 21:51
mveGerry Schmitz19-Dec-20 21:51 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Herboren20-Dec-20 6:09
Herboren20-Dec-20 6:09 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz20-Dec-20 9:30
mveGerry Schmitz20-Dec-20 9:30 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Herboren20-Dec-20 12:47
Herboren20-Dec-20 12:47 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz21-Dec-20 6:52
mveGerry Schmitz21-Dec-20 6:52 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Herboren21-Dec-20 8:31
Herboren21-Dec-20 8:31 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz21-Dec-20 8:57
mveGerry Schmitz21-Dec-20 8:57 
QuestionHow to make connection with SQL Server on another computer? Pin
Alex Dunlop17-Dec-20 9:14
Alex Dunlop17-Dec-20 9:14 
AnswerRe: How to make connection with SQL Server on another computer? Pin
BabyYoda17-Dec-20 9:20
BabyYoda17-Dec-20 9:20 
AnswerRe: How to make connection with SQL Server on another computer? Pin
DerekT-P17-Dec-20 10:16
professionalDerekT-P17-Dec-20 10:16 
QuestionComboBoxItem in another Form Pin
AnissGharib4917-Dec-20 2:09
AnissGharib4917-Dec-20 2:09 
AnswerRe: ComboBoxItem in another Form Pin
Dave Kreskowiak17-Dec-20 3:56
mveDave Kreskowiak17-Dec-20 3:56 
AnswerRe: ComboBoxItem in another Form Pin
OriginalGriff17-Dec-20 4:40
mveOriginalGriff17-Dec-20 4:40 
AnswerRe: ComboBoxItem in another Form Pin
Gerry Schmitz17-Dec-20 4:48
mveGerry Schmitz17-Dec-20 4:48 
AnswerRe: ComboBoxItem in another Form Pin
Herboren18-Dec-20 10:55
Herboren18-Dec-20 10:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.