print winform screen - c#

I have c# winform application.
I want to print all form objects, labels,textboxes etc..
Capture screen is not the solution for me because my form has scroll.
How can I do this?
Thanks.

A simple google search:
http://msdn.microsoft.com/en-us/library/aa287529%28VS.71%29.aspx

This just doesn't work. It is pretty inappropriate anyway, the resolution of the printer is much better than the resolution of your screen. The screenshot looks very ugly on paper, especially text gets blobby with the anti-aliasing pixels becoming painfully obvious.
Bite the bullet and drop the PrintDocument component on the form. You typically need to write a fair amount of code in the PrintPage event handler. But it isn't hard code and it will look great and you can make it look just the way you want it. Be sure to make it look like a report, not a screenshot. Use PrintPreviewDialog to avoid wasting a lot of paper. Report generators like RDLC and Crystal Reports are common solutions as well.

try this it will make a bitmap of your form `
Bitmap b = new Bitmap(this.Bounds.Width, this.Bounds.Height);
this.DrawToBitmap(b, new Rectangle(0,0,this.Width,this.Height));
b.Save("C:\\a.bmp");`
by this image you can print also rather than saving it...

Related

WPF Printing Large Canvas over multiple Pages

I've got this problem:
I created a pretty large Canvas in WPF with a lot children.
I want to add a Print Button. PrintVisual seems not to work, because the image is to big. (I am using a scrollbar) I want to split the Canvas between multiple pages.
What i've done so far:
I am taking a Visual Brush for every part of the Canvas
Create a new Canvas and make the visual brush its background
Adding the new Canvas to a page, add the page to a FixedDocument.
Well, now i've got a FixedDocument and going to print it via printDocument.
The Problem is, that the whole process of printing takes a lot of time and sometimes it doesn't work at all. It's like there is a preprocessing step to convert the fixed document into a bitmap.
My Question: Is a Visualbrush in a Canvas to big? Should i convert the Canvas first into a bitmap?
I've found this great article: http://www.codeproject.com/Articles/339416/Printing-large-WPF-UserControls.
Whatever.
Is it a good way to convert a huge canvas into a bitmap first and then print parts of the bitmap? I could very well imagine, that one could get problems with blurring effects this way.
I've got also no idea how to add a bitmap to a page in wpf.
The worst thing is, that i couldn't found some really good sorces or a standardway (and i think there has to be one, cause this should be a pretty standard problem) for printing dynamic produced canvas in wpf.
I am really greatful for every really good source, help or code.
Thank you for your time.

Improving clarity of images in PictureBox C#

I have Panel on windows form containing labels for displaying information and 2 PictureBox controls. One for Company logo & other for captured photo. When i print them either on Printer or just save in PDF format, both images looking very blur. I want to improve quality of images. So they will appear clear even after zoom.
Any suggestion.
You can set this property of the Graphics object.
// g is type of Graphics.
g.InterpolationMode = InterpolationMode.High;
I don't know which technique you are using for printing but if you are using print form it is not good for decent picture or text. Therefore when you send form/PictureBox to the print object it would lose quality.The Solution is to use PrintDocument.
Share your code for more help.
Your printer has better resolution than your monitor. That bitmap won't work. You will have to recreate the print items directly on the e.Graphics of the PrintPageEventArgs.
Other work around is the technique that guy explain in his article.
http://www.dahuatu.com/3vy2K5z5mr.html

How to print panel with windows form

I need to print a panel(with many subpanel like tablepanellayout) in windows form.
I have seen many solutions such as draw as bitmap with capture screen - that give me correct form but my text and image is very blurred or draw by access all controls in that panels and draw by string or bitmap , it okays but I think it must have better solution.
Thx for read my problem and very thx for giving me a nice solution.
if you dont like the approach of bitmap image. what can be done is use of reportviewer and design the content you want to print. and Pass on the Data to the report viewer. there you can have the flexibity to print as well as export to other formats.
A Sample can be found in the following link to get started.
Click on this Link

How to print GDI+ objects with correct dimensions?

I need to develop an application to print labels previously created with an editor. Each labels has some graphic objects, like images, barcodes, texts,... and when I use the GDI+ drawing methods to print in a PrintDocument, the result is that the object dimensions are always smaller than what I expect. What unit of measure I should use for the objects? What is the best practice for printing objects with GDI?
Any help would be pleasant.
Thanks in advance.
Your question is not very detailed and lacks code example of what you have so far, but anyways. It seems like you have issues setting up your print graphics. You would have to define how to map your graphics to e.g. 300dpi print document.
If you would just google for your question about how to print something with GDI+ you'll find tons of examples and tips like this
http://www.codeproject.com/Articles/2648/Printing-using-GDI-a-few-tips
:edit
if you have millimeter as unit, you can tell your graphics object to use it by defining
gr.PageUnit = GraphicsUnit.Millimeter;
crystal report would be your solution.

Resizing an image after loading it from the database using asp.net, C#

I have a user-uploaded image pulled from the database that I am resizing smaller to display on a web page that I intend to print. I thought about saving a smaller version when the user uploads it, but since the design of this document hasn't been finalized yet, I was looking for something more dynamic. Also, this document only needs to be printed up once, while the image uploaded is displayed at various places in the app numerous times.
Using javascript to resize it while keeping its proportions, it was printing fine for a while. After adding a margin for styling, the printer started printing the image at its full size. I'm assuming it's the margin. It looks fine on screen but pushes everything off the page on paper.
This led me to look into resizing it on the server, in the C# code, but we use user images uploaded to the database, and I can't seem to find the right time or place in the page life cycle to access and change the width and height. I've tried the various methods on the web using Bitmaps, but they all want a file, when I am using a FileDownloader page as the image url.
Perhaps I'm looking in the wrong place entirely and need to go back to the client. Advice and help is appreciated.
As long as your FileDownloader page returns the proper resized image, it shouldn't matter that you're not point to an actual image.
I'd something like this in your FileDownloader page (pseudo code):
using (Image img = LoadImageFromDatabase())
{
using (Image resized = ResizeImage(img))
{
Response.Clear();
// Set proper headers
using (MemoryStream ms = new MemoryStream())
{
resized.Save(ms); // maybe the function isn't called Save, can't remember a 100%
ms.Seek(0); // Can't remember if this is necessary
Response.BinaryWrite(ms);
}
}
}
Like I mentioned it's highly pseudo code, but it should be straight forward with a Visual Studio open, I just haven't access to it right now, and it's been quite a while since I last used this (since I'm stored the resized images like most other in this question recommends - I do so too, however I realize this is not an option for you)
When you are going to have to resize an image to known constraints, and there's the possibility of having to do that multiple times, I'd always advocate doing the resize once (on upload) and storing the result. Of course, you don't say that you need to retain the original image size, but if you do, then you just have to store the image twice - once original size and once at the resized dimensions.
Once you've done that, you can worry about defining your print layout based on the known dimensions of the resized image, and not have to faff about resizing for each use.
I would suggest converting on upload and possibly saving both images in case you want to let the user click through to the full image. Using this model you only do the conversion once and can render either size image. The GetThumbnailImage() method on the Image class will do what you desire, something like this:
String imageFile = uploadedFileName;
Image baseImage = Image.FromFile(imageFile);
Image thumbImage = baseImage.GetThumbnailImage(300,300,..., ...);
SaveMyImage(baseImage);
SaveMyImage(thumbImage);
Be sure to check the documentation for the parameters to GetThumbnailImage() to verify scaling issues and callback handling.
Could you implement such a process:
User sends an image
Image is opened by a function/routine/script, while the user waits
Image is resized on the fly and saved in the correct location which returns a code for success
User receives a message depending of the return value of the script.
EDIT:
I agree with most of the replies you got here.
If the pictures are stored in a database you need to first make thumbmails for all pictures and put them in the same database, then you need to implement a process to create the thumbmails on the fly when adding new pictures.
Disclaimer: I'm suggesting the open-source library I designed for this purpose. I'm definitely biased, but 4 years and thousands of happy users justify my bias :)
You shouldn't be resizing images inside an .ASPX page, or serving them either. Images should be handled in separate requests by a HttpModule so responsiveness doesn't suffer.
If you have some kind of ID in SQL for each image, you can use the SqlReader VirtualPathProvider to make it accessible via a URL, like /sqlimages/id
Combine that with this free, open-source dynamic image resizing module, and you're set.
You'll simply reference images like this: http://localhost/sqlimages/id?width=300&height=200 from your HTML, and you may not even have to write a line of C#.
If you write your own solution, read these 28 pitfalls you should avoid, so you don't end up crashing the server.
Hope this helps!

Categories

Resources