Avatar of Kevin Terry
Kevin TerryFlag for United States of America

asked on 

WinForms, VB.Net, Microsoft ReportViewer

I posted a question a couple of days ago and am very thankful and grateful for the many replies. Unfortunately I was not able to get my printed report to print as advertised. Now I'm going in a different direction.

My original plan was to create a 4"x6" WinForm Panel, add all kinds of text as I cycled through the rows of a CSV file. Every time I updated the Panel with different values, I was printing the 4x6 label to a laser printer. With the difference in the dpi/resolution after i created a bitmap from the panel and to when the ink made itself to the paper, the paper image of my panel was blurry.

Sooooo, I am going down another path. I thought I would try Microsoft ReportViewer and see if that would be any better. Since I have never used the ReportViewer before, it appears to be asking for a database. My printed labels do not lend themselves to a tabular format. There's pieces of data all over the label.

Looking for recommendations on the setup of the label. If the Microsoft ReportView is truely needing a db, recommendations on a lite db to read the csv into. Since I can't use a tabular format, does this mean, I'll need a single value reports, and place several reports around on my label to get the format I need? 
Visual Basic.NET* Forms APIDatabases* report viewer

Avatar of undefined
Last Comment
Kevin Terry
Avatar of Bembi
Bembi
Flag of Germany image


I guess your problem with the form has possibly to do with the resolution. Therefore nur sure if you get better result usinf Reposting Services, which belong to MS SQL Server.

Just let me point into another direction.
Any form you create on the sceen is sticked to the screen resolution. If it is printed it has to translated into the dot matrix of the printer. While a sceen has (usually) a 16:9 relation, the printers usually us a equal matric, i.e 1200 x 1200dpi.
So you have to create a graphical view which has a equal dot matrix like the printer. Otherwise the printer has to interpolate dots and that may make the output blurry. A similar effekt, if you are far away from the printer resolution. I.e. 150x150 dpi on screen and 1200x1200 on printer.
Form are usually not used for printing, so Reporting Services a bit more close.

But you may also think about printing directly onto the printer...(what is some effort of course).
The other option is to use a label printer and at least brothers adds a good software package, which is capable even to read from data sources.
Just a thought.

Windows doesn't really know anything abut 4" x 6" dimensions. Windows only knows about pixels
Your printer driver does know about paper sizes.
Why are you converting to bitmap?
Avatar of Kevin Terry
Kevin Terry
Flag of United States of America image

ASKER

Ok, my panel is 384x576, which I think is equivalent to about 4"x6". I'm trying to use the PrintDocument in the examples I've seen uses a bitmap to print. Possibly if I knew how to print directly from the panel straight to the printer I wouldn't have this issue.
Here's my previous post. Solved: BLURRY TEXT - WINDOW FORMS - PANEL - VB.net | Experts Exchange (experts-exchange.com)  not really solved
I've heard printing directly from panel to printer is quiet involved and difficult, so I'm still searching. 

ASKER CERTIFIED SOLUTION
Avatar of Bembi
Bembi
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Kevin Terry
Kevin Terry
Flag of United States of America image

ASKER

I'm creating a specialized looking label with barcodes on it. So not only is the text blurry, the barbodes are as well. I eyes have been really opened the past couple of days with my posts and reading the comments. I would have thought that if i had a 384x574 panel and I printed it onto the same size sheet it would be a 1:1 ratio. I was going to buy/rent a label printer, but I was told a printer is a printer, just tell your printer what size sheet you are printing. So I purchased my first laser printer. haha I guess depending on the complexity of what would be involved, I may look the other way, but what would I search for if i wanted to see some examples of printing directly from a winform panel directly to a printer? 
Avatar of Bembi
Bembi
Flag of Germany image

Hello Kevin,
yes, at the end a lable printer is printer, this is correct so far. And it works more or less like any other printer.
But the difference is that the software which is possibly provided with the printer is able to print clear and sharp results. And a least my brother software is able also to read data from a datasource, you just palce palceholders into the label.
To create the barcodes i guess you have a tool, they produce usually also picures.
We have done this is the past with word documents, where we included barcodes and the printout was fine and sharp enough to be regognized by bar code readers.
So possibly also an option to use just Word and insert your label there?       
Avatar of Kevin Terry
Kevin Terry
Flag of United States of America image

ASKER

Wow, I hate these kind of posts like this when I have no clear and definite solution. My WinForm app is designed so that a user can select a CSV file that is filled with the barcode information, and as my app cycles through the rows, it updates the panel objects (labels) and then I am creating the bitmap which is sent to the printer through the PrintDocument. Could print hundreds at a time. Sounds like I know what I'm talking about and am an expert, but honestly the opposite. Program mostly from examples. :(
Avatar of Bembi
Bembi
Flag of Germany image

Yes, sometimes solutions are easy, but sometimey you just have to be aware about what happens in the background to find s solution which works as expected.
So starting back to your form.
You said you sized it to 384x574, I assume pixels.
The sceen calculates in pixels as these are the dots (LCD elements) in you monitor which can directly addressed.
If you set a different sceen reolution than the monitor has, also the creen gets blurred as there is no 1:1 relation between monitor and visible screen, The graphic driver has to correct this mismatch and  start to interpolate, what means sometimes it takes one pixel, other times two. 
A common sceen resolution is 1920 x 1080 (Full HD)

Let say your printer is set to 300 dots per inch (what is a common default setting. This means, calculated on a standard printer size of A4 = 21 cm ( 8,27 inches) = 2400 dots over the width of the page.
Or in other words a 4 x 6 inch label would have 1200 x 1800 dots on the printer.

This label fills more or less a half of the sceen width and is double than you sceen height, if you calculate a 1:1 relation between dots and inches...
As far a the printer gets less pixels than it can print, the printer has to interpolate in the same way than with a non fitting sceen resolution, So for a label with 384 pixel, the relation is 1200/384 = 3,125. Means there is no 1:1 relation and the printer has to print 3 sometimes 4 dots for each pixel. If you calculate with 600dpi its 6,25, 1200dpi is 12,5 and 2400 dpi would be 25. So for your label size, the printer needs a resolution of 2.400 dpi to have a fitting relation between pixels and dpi. The printer prints 25 dots for each pixel.  
But as this is a lot of calculation work, most printers default to 300 dpi, nevertheless they are capable to print 2400 dpi or even much more. 

If you define a paper size in the printer, the printer driver is aware about the dots which are available. Each printer has a DEVMODE structure which can be used read the actual settings or to change them, it is the same as you set them via the printer properties or via the control panel on the printer. Beside this, the printer has also some capabilities i.e to replace sceen fonts by printer fonts or to print in graphic mode. If you print in graphic mode, the printer has the same problem than yoz have with your form, the size dosn't fit and the printer interpolates to get the graphic onto the paper. Replacing the sceen fonts by printer fonts allows the printer to use its own fonts, which fits better to the printer matrix and are usualy more sharp.

If you want to stay on your Forms solution, you may get better results, if you give the form more pixels. Means you have to make it larger. The second point is, you should not calculate in sizes, you should calculate in pixels. The printer driver settings (paper size) determined the size on the paper. 
So every value of 300, 600, 1200 will fit better to the printer matrix than your values. On the other hand, because these size will then not fit anymore to the pixel matrix of your sceen, it may look a bit blurred on the sceen.

With your bacode it is the same calculation, if it is a bitmap, the bitmap as it should match the 300 dpi raster as well as the placement on your label should fit to this. So if you have a 300 dpi picture and scale it to 384 pixel, it is not blurred only on the sceen, it is blurred again when calculated back to the printer matrix.
So if your barcode has a 300 dpi resolution, and you scale down the barcode picture to 150 pixels on the form, the monitor will leave every second line away. If you then sent the form to the printer, you have only around 150 dpi left for your barcode. 

So there are some options to get better printout results if you prepare your form fitting to the printer, not to the sceen.
Also you have some options with the printer settings as it, ie. to raise the dot matrix to get a better fitting between sceen and printer. Sometimes the graphic mode works better, sometimes the non graphic mode, black/white mode versus gray mode (what controls interpolation) etc. 

And at the end, if you have only 384x574 pixels on the screen, this is what you deliver to the printer. Set printer ist not able to raise the resolution, it can only print several dots for each pixel.    

Another option I'm not quite clear about the effect, but there a also some new properties in dot net what may influence the results:
https://docs.microsoft.com/en-us/dotnet/desktop/winforms/high-dpi-support-in-windows-forms?view=netframeworkdesktop-4.8  

 
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Between the two questions it appears the problem is due to converting things to an image and trying to print that.

Why do you need the image?

I'm not sure how complex the things are you are printing but easiest for the barcode is to just change the font to a barcode font.  Google: 3 of 9 font


Most printed labels follow specific templates, normally Avery.

So, if you look for code on how to print avery labels, there are several references.

This one just happens to also print USPS barcodes:
How to create Avery Address Labels in WPF with C# or VB.NET featuring USPS Postnet Barcodes

https://www.neodynamic.com/ND/FaqsTipsTricks.aspx?tabid=66&prodid=0&sid=99
Avatar of Kevin Terry
Kevin Terry
Flag of United States of America image

ASKER

Well I'm back. Sorry about replying so delayed.
I have completely ignored the panel and am printing directly to the printer using this....
PrintDocument Class (System.Drawing.Printing) | Microsoft Docs 

It prints everything, line and text crystal clear. The only problem now is, I can't figure out how to print the Code128 BarCode. I am printing the text using Graphics.DrawString(). I've tried changing the font to "Code 128" and "Code128" and neither prints looking like a BarCode, just numbers. I was hoping to just change the font and bingo the BarCode would magically appear on the printer paper. No Dice! Any suggestions as to what I'm doing wrong. Hopefully it's something obvious.
Just listed out all the fonts on my laptop and it only has CCode39_S3. Telling the app to use that font, it does print a BarCode. Now i'm off to find a Free Code 128 Font to download, and not one that comes with a lot of baggage and/or malware etc. 
Avatar of Kevin Terry
Kevin Terry
Flag of United States of America image

ASKER

Found one. Thanks for all the input. 
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo