473,465 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

print the panel control

I would like to print the panel control. The panel
controls contains images and lables.

If i can capture as image i can use it for other purposes
like Zooming etcc..

Any body have any idea ,,, ?
Nov 20 '05 #1
9 7356
* "Kevin" <an*******@discussions.microsoft.com> scripsit:
I would like to print the panel control. The panel
controls contains images and lables.

If i can capture as image i can use it for other purposes
like Zooming etcc..


You will find some code to capture controls here:

<http://www.google.com/groups?selm=sQVN4qGXDHA.2000%40cpmsftngxa06.phx.gb l>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Hi Kevin,

There are two methods that I know for capturing the graphics of a Control.
Both have been included below (for future reference), but only the first will
work for panels.

The first one takes a copy of the Control's surface as it exists. This
means that the Control must be visible and with no other windows on top.

The other one works by fooling the Control into doing its Paint onto a
supplied Bitmap. This works fine for many Controls but not for Panels or
GroupBoxes (and probably not for other container Controls).

In use:
Dim bmpPanel As Bitmap = CaptureControl (pnlSomething)

Regards,
Fergus

<code>
'================================================= ==============
Public Const SRCCOPY As Integer = &HCC0020

Public Declare Function BitBlt Lib "gdi32" ( _
ByVal hDestDC As IntPtr, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hSrcDC As IntPtr, _
ByVal xSrc As Integer, _
ByVal ySrc As Integer, _
ByVal dwRop As Integer _
) As Integer

'================================================= ==============
Public Function CaptureControl(ByVal c As Control) As Bitmap

Dim bmp As Bitmap
Dim gDest, gSource As Graphics
Dim hdcSource, hdcDest As IntPtr

bmp = New Bitmap(c.Width, c.Height)

gSource = c.CreateGraphics
Try
gDest = Graphics.FromImage(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHdc(hdcDest)
End Try
Finally
gSource.ReleaseHdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose()
End Try

Return bmp
End Function

'================================================= ==============
Public Function PaintControlToBitmap (oControl As Control) As Bitmap
Dim OnPaintMethod As MethodInfo
OnPaintMethod = oControl.GetType.GetMethod ("OnPaint", _
BindingFlags.Instance Or BindingFlags.NonPublic)

If Not OnPaintMethod Is Nothing Then
Dim bmpControl As New Bitmap (oControl.Width, oControl.Height)
Dim gr As Graphics = Graphics.FromImage (bmpControl)
Dim PaintEventArgs As New PaintEventArgs (gr, _
New Rectangle(0, 0, oControl.Width, oControl.Height))
OnPaintMethod.Invoke(oControl, New Object() {PaintEventArgs})
gr.Dispose
Return bmpControl
End If
End Function

'================================================= ==============
Public Sub CopyGraphics (gSource As Graphics, gDest As Graphics, _
Width As Integer, Height As
Integer)

Dim hdcSource, hdcDest As IntPtr

hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
gDest.GetHdc, 0, 0, _
Width, Height, _
gSource.GetHdc, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHdc(hdcDest)
End Try
Finally
gSource.ReleaseHdc(hdcSource)
End Try
End Sub
</code>
Nov 20 '05 #3
Hello Fergus

I used the first one..

Dim bmpPanel As Bitmap = CaptureControl

It save a black image which has nothing in it.. can you
please suggest me.. what could be the problem
Nov 20 '05 #4
Hi Kevin,

Having tested the code before I posted it, and on several Controls - Panel
(filled), GroupBox (stuffed), RichTextBox, etc, I know that it works. **

The only conditions required are that the Control <must> be visible. If
<you> can see it then CaptureControl should see it too.If this is the case
then I'm not sure what to suggest, other than to send me the project.

If you need to send me the project, make a copy and cut it down to the
bare minimum (just one form preferably) and zip it without any bin or obj
directories.

Regards,
Fergus

** Famous last words?? I shall test with a new project, using the code as I
gave it to you.
Nov 20 '05 #5
Kev
I've send the project. Thanks
Nov 20 '05 #6
Kev
It works fine.. Sorry for the confussion .. I put wrong
destination and source in the BitBlt function

I've another problem.. I need to print the entire
invisible area of the panel also.. Is there any way i can
do that...

Thanks a lot

-----Original Message-----
Hi Kevin,

Having tested the code before I posted it, and on several Controls - Panel(filled), GroupBox (stuffed), RichTextBox, etc, I know that it works. **
The only conditions required are that the Control <must> be visible. If<you> can see it then CaptureControl should see it too.If this is the casethen I'm not sure what to suggest, other than to send me the project.
If you need to send me the project, make a copy and cut it down to thebare minimum (just one form preferably) and zip it without any bin or objdirectories.

Regards,
Fergus

** Famous last words?? I shall test with a new project, using the code as Igave it to you.
.

Nov 20 '05 #7
Hi Kev,

No worries, I was expecting/hoping that it would be some little glitch.

What do you mean by the invisible area of a Panel?

Regards,
Fergus
Nov 20 '05 #8
Kev
My control height is more than the forms height. SO I use
form's scrollbar to view the rest of it.

Now with your help .. I can capture the image of visible
portion of the pannel. But my panel has more images which
can be viewable only through the form's scrollbar.

FYI: I use the panel to allow the user to desgin their
layout and save it in the database. I keep objects like
picturebox and lable to acheive this... I should allow
them to print their layout. Another requirement is they
should ZOOM also. I don't know how to provide this, So I
thought of capturing the entire panel so that that they
can print and zoom what they want..

Your help in this matter is really appreciated
Nov 20 '05 #9
Hi Kev,

This problem has been a bane for many people, in this and other
newsgroups. It seems like such a reasonable request.

The problem with methods like the one in CaptureControl is that, as far as
I understand it, they are working with screen bitmaps, or at least what is
destined to go to the screen. Thus anything that is out of sight will not be
rendered - namely stuff that is underneath another window, scrolled out of
sight (like your panel) or on a part of a virtual desktop that isn't on the
monitor (we tried that as a solution, but no joy). This makes sense but isn't
useful when the missing bit is what you want.

One workaround for your case is simply to scroll the Panel to the top,
capture it, then scroll it down, capture the remainder, sew them together and
then scroll hte Panel to where the User left it. It will appear as a flicker
to the user, I suppose. (You might need to add a DoEvents or Panel.Refresh to
make it work).

That word zoom got me going there. Our very own Cor had a query about
working with photos a few days ago. I wrote him a demo which does cropping and
zooming. Basically there's a thumbnail view and a selection rectangle drawn on
it. Whatever's in the rectangle will be copied to the main picture (thus the
cropping) and the rectangle can be dragged around as required. The zooming
part is handled by shrinking and enlarging the selection rectangle (and then
moving it around to centre it nicely).

It seems to me that you might be able to bend that technique to suit your
purposes. But instead of cropping a bitmap, you use the zoom to scale the
Controls. There's an attachment in Cor's query (Topic: newbie question about
graphics, dated 28th Oct) which contains the code. It might give you some
ideas. (It was a single night's work so it works but the code is fairly raw).

I'd be interested to discuss this further. I'd be especially keen to see
it in action, if you wouldn't mind. A project sent to my email address would
be welcomed (no obj or bin).

Regards,
Fergus
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fabrizio | last post by:
Hi, There is any chance to insert a control like a text box in a panel choosing the absolute position? When I try to insert a label , the panel positions the control on a locked position. Thanks...
1
by: Tia Carr | last post by:
When I try to place a child control on top of a panel control, the mouse pointer remains as a pointer instead of changing to a cross. I tried both the ShowGrid on/off, doesn't make a difference.....
1
by: simon | last post by:
How can I print the <asp:panel > contents to the printer on the client? If I use vbscript and window.print then all page is printed not only panel. Thank you, Simon
9
by: Bill Long | last post by:
I have a control that simply displays a list of links. Following one of the links doesn't post back or redirect to another page, it simply hides the current panel and shows the one you selected......
11
by: BoloBaby | last post by:
OK, check this out... I have a form with a panel control and button on it (outside the panel control). I have two event handlers - one handles the click event of the button on the form. The...
2
by: topdawg147 | last post by:
I'm trying to build a custom control that includes a panel control on it. However, in design-time when I drag a new control (e.g. a textbox, etc) into the panel, it's not added in the panel--just...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
0
by: kaymaf | last post by:
Hi , i wrote an application to make ID Card, i used textbox, label and picturebox on a panel. i want to print the panel and the control on it but when i preview the document, the image on the...
0
by: thirunavukarasukm | last post by:
Hai... Problem in Print Friendly Version with treeview control... i am creating one web applications.. in this web application in main page The left side one panel and right side one Iframe...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.