473,761 Members | 9,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing controls

Hi!

I have a panel formed as an A4-page, in this panel I have som labels,
pictureboxes and a datagrid. How can I print the complete panel vith all it's
controls?

Regards
Anders Aleborg
Nov 16 '05 #1
7 10199
Hi Anders,

Try this link from MSDN:
http://msdn.microsoft.com/library/en...intsupport.asp

There are a number of samples including one on datagrid as well.

HTH,
Rakesh Rajan

"an****@aleborg .se" wrote:
Hi!

I have a panel formed as an A4-page, in this panel I have som labels,
pictureboxes and a datagrid. How can I print the complete panel vith all it's
controls?

Regards
Anders Aleborg

Nov 16 '05 #2
All I can find is how to print a complete form, text or graphics not anything
about different controls. I've managed to print a datagrid but it only ends
up in the left corner, not where I tried to place it using location.

"Rakesh Rajan" wrote:
Hi Anders,

Try this link from MSDN:
http://msdn.microsoft.com/library/en...intsupport.asp

There are a number of samples including one on datagrid as well.

HTH,
Rakesh Rajan

"an****@aleborg .se" wrote:
Hi!

I have a panel formed as an A4-page, in this panel I have som labels,
pictureboxes and a datagrid. How can I print the complete panel vith all it's
controls?

Regards
Anders Aleborg

Nov 16 '05 #3
Hi Anders,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to print the controls in the
panel to a printer. If there is any misunderstandin g, please feel free to
let me know.

Based on my experience, we have to achieve this with 2 step. First, we've
got to convert the panel control to a bitmap image. Second, we print it to
the printer.

Here is a code snippet that can do the convertion from certain control to a
bitmap.

Private Sub MenuItem2_Selec t(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MenuItem2.Selec t
Dim g1 As Graphics
g1 = Me.CreateGraphi cs()
Dim MyImage As Image
MyImage = New Bitmap(Me.Width , Me.Height, g1)
Dim a As Int32
a = Me.Height
Dim g2 As Graphics
g2 = Graphics.FromIm age(MyImage)
Dim dc1 As IntPtr
dc1 = g1.GetHdc()
Dim dc2 As IntPtr
dc2 = g2.GetHdc()
BitBlt(dc2, 0, 0, Me.Width, Me.Height, dc1, -4,
Me.ClientRectan gle.Height - Me.Height + 4, 13369376)
g1.ReleaseHdc(d c1)
g2.ReleaseHdc(d c2)
Dim p As Point
p.X = Me.MousePositio n.X - Me.Location.X
p.Y = Me.MousePositio n.Y - Me.Location.Y
Me.Cursor.Draw( g2, New Rectangle(p, Me.Cursor.Size) )
MyImage.Save("c :\saved.jpg", Drawing.Imaging .ImageFormat.Jp eg)
MessageBox.Show ("Finished Saving Image")
End Sub

Private Declare Auto Function BitBlt Lib "GDI32.DLL" _
(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean

If you just need to print it, you needn't save it to a file. Just pass it
to print document as the MSDN document mentioned that Rakesh provided.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4
Hi Kevin, thanks!
Correct me if I'm wrong, your code saves the form including the mousepointer
to a file :)
So let's say I need to get a panel into the image instead and some labels,
how do I add the labels to the image?
The code in C# without the mousepointer:

Graphics g1 = this.CreateGrap hics();
Image MyImage = new Bitmap(panel1.W idth,panel1.Hei ght,g1);
int a = panel1.Height;

Graphics g2 = Graphics.FromIm age(MyImage);
System.IntPtr dc1 = g1.GetHdc();
System.IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, panel1.Width, panel1.Height, dc1, -4,
this.ClientRect angle.Height - panel1.Height + 4, 13369376);
g1.ReleaseHdc(d c1);
g2.ReleaseHdc(d c2);

How do I translate this to C#?
Private Declare Auto Function BitBlt Lib "GDI32.DLL" _
(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean

Regards
Anders ALeborg

"Kevin Yu [MSFT]" wrote:
Hi Anders,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to print the controls in the
panel to a printer. If there is any misunderstandin g, please feel free to
let me know.

Based on my experience, we have to achieve this with 2 step. First, we've
got to convert the panel control to a bitmap image. Second, we print it to
the printer.

Here is a code snippet that can do the convertion from certain control to a
bitmap.

Private Sub MenuItem2_Selec t(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MenuItem2.Selec t
Dim g1 As Graphics
g1 = Me.CreateGraphi cs()
Dim MyImage As Image
MyImage = New Bitmap(Me.Width , Me.Height, g1)
Dim a As Int32
a = Me.Height
Dim g2 As Graphics
g2 = Graphics.FromIm age(MyImage)
Dim dc1 As IntPtr
dc1 = g1.GetHdc()
Dim dc2 As IntPtr
dc2 = g2.GetHdc()
BitBlt(dc2, 0, 0, Me.Width, Me.Height, dc1, -4,
Me.ClientRectan gle.Height - Me.Height + 4, 13369376)
g1.ReleaseHdc(d c1)
g2.ReleaseHdc(d c2)
Dim p As Point
p.X = Me.MousePositio n.X - Me.Location.X
p.Y = Me.MousePositio n.Y - Me.Location.Y
Me.Cursor.Draw( g2, New Rectangle(p, Me.Cursor.Size) )
MyImage.Save("c :\saved.jpg", Drawing.Imaging .ImageFormat.Jp eg)
MessageBox.Show ("Finished Saving Image")
End Sub

Private Declare Auto Function BitBlt Lib "GDI32.DLL" _
(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean

If you just need to print it, you needn't save it to a file. Just pass it
to print document as the MSDN document mentioned that Rakesh provided.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5
Hi Anders,

For defination in C#:

[DllImport("gdi3 2.dll", ExactSpelling=t rue, SetLastError=tr ue)]
public static extern Bool BitBlt(
IntPtr hObject,
int nXDest, int nYDest,
int nWidth, int nHeight,
IntPtr hObjSource, int nXSrc, int nYSrc,
int dwRop);
Luke

Nov 16 '05 #6
Hi!

I solved it in another way:

private void DrawAll(Graphic s g)
{
RectangleF srcRect = new Rectangle(0, 0, this.panel1.Wid th,
panel1.Height);
int nWidth = 802;
int nHeight = 1104;
RectangleF destRect = new Rectangle(0, 0, nWidth, nHeight);

float scalex = destRect.Width/this.panel1.Wid th;
float scaley = destRect.Height/this.panel1.Hei ght;

GraphicsUnit gu = GraphicsUnit.Pi xel;
RectangleF scaledRectangle ;
Brush br = new
System.Drawing. SolidBrush(Colo r.FromArgb(((Sy stem.Byte)(74)) ,
((System.Byte)( 74)), ((System.Byte)( 74))));

scaledRectangle = GetScaledRectan gle(scalex, scaley, pictureBox1.Bou nds);
Image my1Image = (Image)pictureB ox1.Image.Clone ();
g.DrawImage(my1 Image, scaledRectangle ,pictureBox1.Im age.GetBounds(r ef
gu), GraphicsUnit.Pi xel);

scaledRectangle = GetScaledRectan gle(scalex, scaley, pictureBox2.Bou nds);
Image my2Image = (Image)pictureB ox2.Image.Clone ();
g.DrawImage(my2 Image, scaledRectangle ,pictureBox2.Im age.GetBounds(r ef
gu), GraphicsUnit.Pi xel);

scaledRectangle = GetScaledRectan gle(scalex, scaley, pictureBox3.Bou nds);
Image my3Image = (Image)pictureB ox3.Image.Clone ();
g.DrawImage(my3 Image, scaledRectangle ,pictureBox3.Im age.GetBounds(r ef
gu), GraphicsUnit.Pi xel);

if(pictureBox4. Visible && pictureBox5.Vis ible)
{
scaledRectangle = GetScaledRectan gle(scalex, scaley, pictureBox4.Bou nds);
Image my4Image = (Image)pictureB ox4.Image.Clone ();
g.DrawImage(my4 Image, scaledRectangle ,pictureBox4.Im age.GetBounds(r ef
gu), GraphicsUnit.Pi xel);

scaledRectangle = GetScaledRectan gle(scalex, scaley, pictureBox5.Bou nds);
Image my5Image = (Image)pictureB ox5.Image.Clone ();
g.DrawImage(my5 Image, scaledRectangle ,pictureBox5.Im age.GetBounds(r ef
gu), GraphicsUnit.Pi xel);
}

foreach(Control x in this.panel1.Con trols)
{
if(x.GetType(). ToString() == "System.Windows .Forms.Label" && x.Visible)
{
Label theText = (Label)x;
x.BringToFront( );
StringFormat drawFormat = new StringFormat();
if(theText.Text Align.ToString( ) == "TopRight")
{
drawFormat.Alig nment = StringAlignment .Far;
g.DrawString(th eText.Text, theText.Font,br ,
(theText.Bounds .Left+theText.W idth+2)*scalex, theText.Bounds. Top * scaley,
drawFormat);
}
else if(theText.Text Align.ToString( ) == "TopCenter" )
{
drawFormat.Alig nment = StringAlignment .Center;
g.DrawString(th eText.Text, theText.Font,br ,
(theText.Bounds .Left+(theText. Width/2))*scalex, theText.Bounds. Top * scaley,
drawFormat);
}
else
g.DrawString(th eText.Text, theText.Font,br ,
theText.Bounds. Left*scalex, theText.Bounds. Top * scaley, drawFormat);
}
}
"[MSFT]" wrote:
Hi Anders,

For defination in C#:

[DllImport("gdi3 2.dll", ExactSpelling=t rue, SetLastError=tr ue)]
public static extern Bool BitBlt(
IntPtr hObject,
int nXDest, int nYDest,
int nWidth, int nHeight,
IntPtr hObjSource, int nXSrc, int nYSrc,
int dwRop);
Luke

Nov 16 '05 #7
Hi Anders,

It was nice to hear that you have had the problem resolved. Thanks for
sharing your experience with all the people here. If you have any
questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #8

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

Similar topics

2
2476
by: Dragan Kovac | last post by:
Hello everyone, I have a problem. I generated some kind of my own report (by building HTML file) and now I want to print it. Printing itself is not a problem, problem is with adding custom headers and footers on every printed page. How can I do it? Some nice example would be reeeeally great! In header I want to put a picture, some text, and in footer I would like to have page counter and some small text displayed... I've heard...
1
1755
by: slothboy | last post by:
Hey guys, I'm having a little trouble printing subforms. I've attached the snippet of code that prints my form which contains various subforms. It prints bounded controls on the subform just fine, but it does not print unbounded controls. Any advice would be hugely appreciated. I'm sure it is something extremely simple, but I'm a bit new to Access 2000. Thanks so much. stDocName = Me.Name
4
2191
by: Russ | last post by:
To ASP.NET printing experts: My Asp.net web form needs to print some reports at the client side. I've been trying to research this and find some confusing and conflicting information in previous news group answers. Some say "Crystal Reports", others say "PDF" or "Word", and others say that you cannot do this at all on client side??? My reports are text documents that are already formatted, contain form feeds, and positioning controls...
1
5720
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out of a Microsoft book, "Visual Basic,Net Step by Step" in Chapter 18. All but the bottom two subroutines will open a text file, and then allow me to use the above controls, example 1. The bottom two subroutines will print a graphic file, example...
6
2132
by: J Ames | last post by:
I have an ASP.NET (VB) form that has two drop downs, a horizontal rule and a button. The button invokes a stored procedure and several tables are created on the page with data populated. I want to create a link to print the page, but I don't want the drop downs or the button to print, only the tables. How can this be done? I know how to use a CSS file to disallow the entire page from being printed, but I don't know how to apply this to...
8
5912
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic do deliver one <objecttag
2
9976
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default printer settings to print. I wanted the print preview to appear the same for all users (i.e. a default page size of 8.5x14 (legal) and portrait mode). Many users have different printers as their default (plotters etc..) and I found that various...
0
1169
by: dotnet2005 | last post by:
Hi Toall , I want to explain you clearly , I am having some panels having some controls CheckBox,ComboBox,Datagridview,Hyperlink,label,Listbox,Picturebox,RadioButt on ,Textbox) &(Oval,Line,Rectangle ). with .BorderStyle = BorderStyle.FixedSingle . All these things are generating at runtime
18
11311
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing classes, for each of the checked rows in the GridView. This works fine in the Visual Studio 2005 development environment on localhost. But, when I move the page to the web server, I get the error "Settings to access printer...
1
1711
by: varun sharma | last post by:
i have a C# windows application in Visual Studio. I have a form which is opened in a panel.i want to print the data in various controls of the form upon clicking a PRINT button.but i don't want to print the jpg image of the entire form or any of its controls.i want that the text in the controls should be printed.for e.g. i have a label NAME:- and a textbox txtName in front of the label and suppose the user enters the name john in the textbox ....
0
9345
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
9957
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...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
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
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5229
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...
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
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.