Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Graphics.CopyFromScreen() problems

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rory.groves@gmail.com - 12 Jan 2008 03:24 GMT
C#, NET 2.0:

I am using CopyFromScreen to copy a background user control to a
foreground usercontrol to create the appearance of transparency.

It works perfectly 95% of the time. However it only paint what is
visible. So if there is another window on top of the application when
CopyFromScreen is called (such as when first starting the
application), then it paints part of the other window as my
usercontrol background.

Is there any way to export a region of the Graphics object into a
Bitmap without using CopyFromScreen?

Or, is there a CopyFromHDC() or equivalent?

Thanks.
Peter Duniho - 12 Jan 2008 04:56 GMT
> [...]
> Is there any way to export a region of the Graphics object into a
> Bitmap without using CopyFromScreen?

That depends on where you got the Graphics object.  But not per se, no.  
You draw _into_ Graphics objects, not _from_ them.

> Or, is there a CopyFromHDC() or equivalent?

Depending on exactly what you're trying to do, you might want to look at  
Control.DrawToBitmap(), or possibly at using p/invoke to send a WM_PRINT  
or WM_PRINTCLIENT message to the control in question.

It is possible something in WPF would do what you want, but I don't know  
anything about that.

Pete
rory.groves@gmail.com - 12 Jan 2008 15:39 GMT
> That depends on where you got the Graphics object.  But not per se, no.  
> You draw _into_ Graphics objects, not _from_ them.

I do have access to the background control's graphics object, but, as
i mentioned, don't know how to "extract" the controul's bitmap into
another bitmap without using CopyFromScreen().

Here is a simplified representation of my code:

   Rectangle rc = new
Rectangle(this.PointToScreen(foregroundControl.Location),
       foregroundControl.Size);
   using (Bitmap bitmap = new Bitmap(rc.Width, rc.Height,
       PixelFormat.Format32bppArgb))
   using (Graphics g = Graphics.FromImage(bitmap))
   {
       g.CopyFromScreen(rc.Left, rc.Top, 0, 0, rc.Size);
       foregroundControl.BackBitmap = bitmap;
   }
   foregroundControl.Invalidate(true);

Again, to re-iterate, CopyFromScreen() includes overlapping windows
and therefore messes up the foregroundControl's appearance. I need to
figure out how to copy the backgroundControl's bitmap without using
CopyFromScreen.

Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.