473,785 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ 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 7382
* "Kevin" <an*******@disc ussions.microso ft.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=sQV N4qGXDHA.2000%4 0cpmsftngxa06.p hx.gbl>

--
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.CreateGraphic s
Try
gDest = Graphics.FromIm age(bmp)
Try
hdcSource = gSource.GetHdc
Try
hdcDest = gDest.GetHdc
Try
BitBlt( _
hdcDest, 0, 0, _
c.Width, c.Height, _
hdcSource, 0, 0, SRCCOPY _
)
Finally
gDest.ReleaseHd c(hdcDest)
End Try
Finally
gSource.Release Hdc(hdcSource)
End Try
Finally
gDest.Dispose()
End Try
Finally
gSource.Dispose ()
End Try

Return bmp
End Function

'============== =============== =============== =============== ====
Public Function PaintControlToB itmap (oControl As Control) As Bitmap
Dim OnPaintMethod As MethodInfo
OnPaintMethod = oControl.GetTyp e.GetMethod ("OnPaint", _
BindingFlags.In stance Or BindingFlags.No nPublic)

If Not OnPaintMethod Is Nothing Then
Dim bmpControl As New Bitmap (oControl.Width , oControl.Height )
Dim gr As Graphics = Graphics.FromIm age (bmpControl)
Dim PaintEventArgs As New PaintEventArgs (gr, _
New Rectangle(0, 0, oControl.Width, oControl.Height ))
OnPaintMethod.I nvoke(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.ReleaseHd c(hdcDest)
End Try
Finally
gSource.Release Hdc(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
10845
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 Fabrizio
1
2481
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.. Can someone please point out the obvious... I have the 2002 version of VS.NET. TIA
1
1196
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
3187
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... So the behavour is similar to a tab control. The user is expected to fill out required data on each of the panels before pressing a submit button which is visible from all panels. Problem I have is validating the data entered by the user. I...
11
1902
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 other handles a custom "CardInserted" event for a class I wrote that watches for smart cards to be inserted into an attached smart card reader.
2
2055
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 the overall control. * I do not want the entire user control to be a panel/container control. I just want the panel part of it to work as expected. Any suggestions?
8
5370
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 this code there is a panel panel1, that I populate with a lable in the foreground. Then when I click on "button1" a backgroundworker thread in async mode is started. When the backgoundworker thread completes the thread returns a panel to populate...
0
1804
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 pictureBox is far away from the panel.any help
0
1124
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 control.. i am go to run the page the treeview control to expand corresponding page target to iframe control..
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8978
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5383
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.