472,129 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,129 software developers and data experts.

printersettings papersources does not return correct values

I have been trying to figure this out for quite some time and cannot
find any examples in VB.Net or in VB that work correctly. I am working
on an application where I want the user to be able to select a peinter
and printer tray to print reports out. In Crystal Reports 8.5, I can
select a printer and tray and it prints correctly.
I did a test report that I use to tell me the value that Crystal
Reports is using for the paper source. When I use those values in my
program to initialize Crystal, it will print where I expect it to
print. So I know Crystal Reports is able to select the correct printer
and paper source, there are no problems with drivers or anything else,
it works!
Next, I get the values for the paper sources from printersettings.
The values that I'm getting from printersettings are not correct. The
values are different then what I get using Crystal Reports. I have
tried this with a number of printers and I get the same result,
Crystal Reports can get the correct settings but printersettings
can't!
I have even tried using the DeviceCapabilities function in the
Windows API and it does not work either. In a lot of instances,
DeviceCapabilities returned different values then the ones I got using
PrinterSettings.
A couple of years ago I posted a message on the news groups about
this problem. At that time I was using an earlier version of VB.Net
and I could see
a private implementation field for PaperSource. This field, the "kind"
field, showed the correct value for the PaperSource. The "Kind" field,
which is what you can read, gave the wrong value. Microsoft's solution
was to fix .NET so you would not see the "kind" value. For some reason
they chose not to give the correct value in the "Kind" field.
So, I have tried just about everything I could find on the internet
and I still have not found any code that works correctly. Maybe I'll
try doing it in C next! At this point I feel I have exhausted all of
my options with VB and VB.NET.
Has anyone out there been able to get the correct values for the
paper source? There has to be a "correct" way to do this because I
know it works in Crystal Reports and in Microsoft Word.
Jul 21 '05 #1
1 7638
This is a very ugly hack, but you can use reflection to access the
private "kind" field, as shown in the sample below :

For each paperSource in thePrinterSettings.PaperSources
dim rawKind as Integer
rawKind = paperSource.Kind
If paperSource.Kind = PaperSourceKind.Custom Then
rawKind = CInt(paperSource.GetType().GetField("kind",
Reflection.BindingFlags.Instance Or
Reflection.BindingFlags.NonPublic).GetValue(paperS ource))
End If
debug.WriteLine(paperSource.SourceName & " = " & rawKind)
Next paperSource

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Steve Hanna | last post: by
3 posts views Thread by Jochen Kalmbach | last post: by
1 post views Thread by Richard Golebiowski | last post: by
2 posts views Thread by =?Utf-8?B?RGF2aWQ=?= | last post: by
reply views Thread by leo001 | last post: by

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.