Click here to Skip to main content
14,767,936 members
Home » Discussions » C#
   

C#

 
AnswerRe: Why does NullReferenceException throw irrelevantly? I already tried - no success. Pin
Gerry Schmitz22-Dec-20 4:33
mveGerry Schmitz22-Dec-20 4:33 
SuggestionSQLLight vs SQL CE Pin
Alex Dunlop20-Dec-20 9:16
MemberAlex Dunlop20-Dec-20 9:16 
GeneralRe: SQLLight vs SQL CE Pin
Gerry Schmitz20-Dec-20 10:19
mveGerry Schmitz20-Dec-20 10:19 
GeneralRe: SQLLight vs SQL CE Pin
Mycroft Holmes20-Dec-20 12:15
professionalMycroft Holmes20-Dec-20 12:15 
QuestionHow to save panel content into PDF Pin
RedPandinus19-Dec-20 18:46
MemberRedPandinus19-Dec-20 18:46 
AnswerRe: How to save panel content into PDF Pin
OriginalGriff19-Dec-20 20:57
mveOriginalGriff19-Dec-20 20:57 
SuggestionRe: How to save panel content into PDF Pin
RedPandinus19-Dec-20 21:30
MemberRedPandinus19-Dec-20 21:30 
GeneralRe: How to save panel content into PDF Pin
OriginalGriff19-Dec-20 23:57
mveOriginalGriff19-Dec-20 23: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:
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 7:07
MemberRedPandinus20-Dec-20 7:07 
GeneralAForge Motion Detection from PictureBox? Pin
Herboren19-Dec-20 18:15
MemberHerboren19-Dec-20 18:15 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz19-Dec-20 22:51
mveGerry Schmitz19-Dec-20 22:51 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Herboren20-Dec-20 7:09
MemberHerboren20-Dec-20 7:09 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz20-Dec-20 10:30
mveGerry Schmitz20-Dec-20 10:30 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Herboren20-Dec-20 13:47
MemberHerboren20-Dec-20 13:47 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz21-Dec-20 7:52
mveGerry Schmitz21-Dec-20 7:52 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Herboren21-Dec-20 9:31
MemberHerboren21-Dec-20 9:31 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz21-Dec-20 9:57
mveGerry Schmitz21-Dec-20 9:57 
QuestionHow to make connection with SQL Server on another computer? Pin
Alex Dunlop17-Dec-20 10:14
MemberAlex Dunlop17-Dec-20 10:14 
AnswerRe: How to make connection with SQL Server on another computer? Pin
BabyYoda17-Dec-20 10:20
MemberBabyYoda17-Dec-20 10:20 
AnswerRe: How to make connection with SQL Server on another computer? Pin
DerekT-P17-Dec-20 11:16
professionalDerekT-P17-Dec-20 11:16 
QuestionComboBoxItem in another Form Pin
AnissGharib4917-Dec-20 3:09
MemberAnissGharib4917-Dec-20 3:09 
AnswerRe: ComboBoxItem in another Form Pin
Dave Kreskowiak17-Dec-20 4:56
mveDave Kreskowiak17-Dec-20 4:56 
AnswerRe: ComboBoxItem in another Form Pin
OriginalGriff17-Dec-20 5:40
mveOriginalGriff17-Dec-20 5:40 
AnswerRe: ComboBoxItem in another Form Pin
Gerry Schmitz17-Dec-20 5:48
mveGerry Schmitz17-Dec-20 5:48 
AnswerRe: ComboBoxItem in another Form Pin
Herboren18-Dec-20 11:55
MemberHerboren18-Dec-20 11: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.