473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 7732
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: RBisch | last post by:
I am finding that some of the properties off of the PrinterSettings object are misleading For example, When I test the CanDuplex on a printer I know duplexes, the property is false. Another one...
3
by: Steve Hanna | last post by:
I am having problems using the Printer Dialog to set PrinterSettings, specifically the landscape property of the DefaultPageSettings. Here's the code: <code> Private Sub GetPrinter(ByRef...
3
by: Jochen Kalmbach | last post by:
Hello, if an PrinterSettings-Instance is not set-up correctly (for example just by using the default-constructor), then the "ToString()"_method will throw an exception! Unhandled...
0
by: Benoit Courchesne | last post by:
Why when I do this, I get garbage in my dm2 Structure ? PrintDocument pd = new PrintDocument(); IntPtr hDevMode = pd.PrinterSettings.GetHdevmode(); IntPtr pDevMode = GlobalLock( hDevMode ); dm2...
0
by: trint | last post by:
try { // Wait for the report to completely render. if(m_numberOfPages < 1) return false; PrinterSettings printerSettings = new PrinterSettings(); printerSettings.MaximumPage = m_numberOfPages;...
3
by: trint | last post by:
Can someone help me to get this code to work...I'm unsure what the 'printDoc' variable is supposed to be? // Add list of paper sources found on the printer to the combo box. // The DisplayMember...
1
by: Richard Golebiowski | last post by:
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...
2
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.)...
2
by: =?Utf-8?B?RGF2aWQ=?= | last post by:
I’m not sure how to feed PCL commands (i.e. “Ec&l1S”) thru the PrinterSettings() function, but we have been successfully using the PrinterSetting() properties and methods to successfully call...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.