Getting Panel Image

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!
I want to get the image currently displayed in a pannel in order to save it,
draw an icon on it and restore it when the icon is moved.
How can I get the image displayed in a panel or in a form (drawed using GDI+
in the onpaint event)?

Thanks
Cristian Mori
 
See the article on capturing the image of a Windows Forms control in Windows
Forms Tips and Tricks.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
I see that in the tips you use p/invoke on GDI functions.
Is there a way to do so using only managed code?

Thanks
 
You cannot do this with only managed code in 1.1 but 2.0 has a managed
method of doing this which enables you to obtain a bitmap for a control
surface.



--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Here it is in VB:

\\\
Dim bmp As New Bitmap(Me.Panel1.Width, Me.Panel1.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim ev As New PaintEventArgs(g, Me.Panel1.ClientRectangle)
Me.InvokePaintBackground(Me.Panel1, ev)
Me.InvokePaint(Me.Panel1, ev)
ev.Dispose()
g.Dispose()
bmp.Save("C:\Test.bmp")
bmp.Dispose()
///
 
Bob Powell said:
You cannot do this with only managed code in 1.1 but 2.0 has a managed
method of doing this which enables you to obtain a bitmap for a control
surface.

ACK: 'Control.DrawToBitmap'.
 
Hi CristianMori,

Does the community's replies make sense to you? If you still have any
concern, please feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi jeffrey, sorry for replying so late but i was out of office.

I saw that the response in .net 1.1 in negative.
I am writeing a program where you can drag element around the workplace.
Those elements are drawn when dragged, but i had to save the content of the
workplace in order to restore it when the element is moving over.
So I guess the only choice i have is to create a bitmap in memory and use it
as a backbuffer...

Do you have any other advise?

Thanks
Cristian
 
Hi Cristian,

Sorry, but currently, I do not understand your problem context, so I can
not understand your current reply. Can you show me your concern and problem
context in more details?

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Jeffrey, sorry for the long delay.

I have this need: I have a program with a toolbar with some icons.
The user can pick an icon and drop it on the drawing area of the form. This
area is made up with a panel.
Once dropped, the user can still drag it aroung with the mouse. While
dragging, I'd like to save what's under the icon in order to restore it.

pseudocode

OnMouseMove()
{
RedrawPreviousBackgroundInPreviousIconPosition();
SaveBackgroundInNewIconPosition();
DrawIconInNewIconPosition();
}

I hope that now it's clear.
Now I used a bitmap to draw the panel, so I draw on the bitmap and then I
draw the bitmap on the panel. While dragging around the icons i use the last
saved bitmap as sourcedata to replace the area erased by the icon moving, but
I was wondering if there was a better way to do so...

Regards
Cristian Mori
 
Hi Cristian,

I am not sure about what is your concern on this approach. Can you show me
your concern? Currently, I can not think of better solution to it. Maybe
you can post your issue in microsoft.public.dotnet.framework.drawing
newsgroup to see if they have any good suggestion on this.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top