Bạn có thể nhận được các thuộc tính máy in bao gồm các thùng giấy (khay) cho máy in sử dụng windows api: http://msdn.microsoft.com/en-us/library/bb258176(v=office.12).aspx http://www.thedbcommunity.com/index.php?option=com_content & nhiệm vụ = xem & id = 218 & Itemid = 56
Bạn có thể sử dụng lớp iPaper trong ArcObjects SDK 10 Khung Microsoft.NET (tôi không hoàn toàn chắc chắn về cách làm việc này) http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002wn000000
Chỉnh sửa: Chỉ cần mất một cái nhìn sâu sắc vào một trong các liên kết Tôi đưa cho bạn, điều này sẽ là câu trả lời bạn đang tìm kiếm:
// Get Printer Tray Codes for Word Printing using DeviceCapabilities
// By: BB
//
// Inputs:1)strTrayName - Name of the tray to search for, ie "Tray 1", "Tray 2", "Manual"
/// <summary>
/// Gets the printer code for the specified tray, based on the current printer for the Word Document
/// Printer trays on various HP printers change between models and Word documents
/// will not act the same when printed on different printers. This allows us
/// to get the right code for the tray we want to print to.
/// </summary>
/// <param name="strTrayName">Name of the tray to search for, ie "Tray 1", "Tray 2", "Manual"</param>
/// <param name="iDefaultBin">A default bin to return if not found ie. (int)WdPaperTray.wdPrinterUpperBin</param>
/// <param name="wordDoc">A word document object that we want to check the printer for</param>
/// <returns></returns>
public int GetBinNumber(string strTrayName, int iDefaultBin, Word.Document wordDoc)
{
//Code adapted from Microsoft KB article Q194789
//HOWTO: Determine Available PaperBins with DeviceCapabilities API
//Get the printer & port names and numbers of the current printer
//
// Once we have the printer bin we can then use
// InvokeMember on the wordDoc.PageSetup object to set the bin.
//
// Example call to this method is
// int Tray1Code = GetBinNumber("Tray 1",(int)WdPaperTray.wdPrinterUpperBin);
int BinRes;
BinRes = iDefaultBin; //set up a default bin as the lower
try
{
string sPort = wordDoc.Application.ActivePrinter.Substring(wordDoc.Application.ActivePrinter.IndexOf(" on ") + 3).Trim();
string sCurrentPrinter = wordDoc.Application.ActivePrinter.Substring(0, wordDoc.Application.ActivePrinter.IndexOf(" on ")).Trim();
//'Find out how many printer bins there are
Int32 iBinCnt = DeviceCapabilities(sCurrentPrinter, sPort, DC_BINS, null, IntPtr.Zero);
if (iBinCnt > -1)
{
//'Set the array of bin numbers to the right size
UInt16[] iBinArray = new UInt16[iBinCnt];
//set up a buffer to receive the bin names - each name is up to 24 chars, null terminated
byte[] buffer = new byte[iBinCnt * 24];
// Load the array with the bin numbers
iBinCnt = DeviceCapabilitiesA(sCurrentPrinter, sPort, DC_BINS, iBinArray, IntPtr.Zero);
if (iBinCnt > -1)
{
// Load the array of bin names
iBinCnt = DeviceCapabilitiesA(sCurrentPrinter, sPort, DC_BINNAMES, buffer, IntPtr.Zero);
if (iBinCnt > -1)
{
string sBinNames = Encoding.ASCII.GetString(buffer, 0, buffer.Length);
//split the null terminated strings into a string array for searching
while (sBinNames.IndexOf("\0\0") > -1)
{
sBinNames = sBinNames.Replace("\0\0", "\0");
}
string[] arrBinNames = sBinNames.Split('\0');
//System.Diagnostics.Debug.WriteLine("prn nams = " + res);
int idx = 0;
foreach (string BinNam in arrBinNames)
{
if(BinNam.Trim().StartsWith(strTrayName))
{
BinRes = iBinArray[idx];
break;
}
idx++;
}
}
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Error - " + ex.Message);
}
return BinRes;
}
sao chép một phần từ trang web do những hạn chế, bạn có thể xem toàn bộ mã tại đây:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3687&lngWId=10
Nguồn
2011-07-18 14:17:45
Có ứng dụng web hoặc WPF không? – Ankit
Dự án Winforms của nó – PeteT
Chỉ cần suy nghĩ .. nếu bạn chỉ tìm kiếm khay tốt nhất cho công việc in, tại sao không chỉ sử dụng khay lớn nhất và chỉ định khổ giấy ?? –