本文整理汇总了C#中System.Drawing.Printing.PrinterSettings.SetHdevmode方法的典型用法代码示例。如果您正苦于以下问题:C# PrinterSettings.SetHdevmode方法的具体用法?C# PrinterSettings.SetHdevmode怎么用?C# PrinterSettings.SetHdevmode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Printing.PrinterSettings
的用法示例。
在下文中一共展示了PrinterSettings.SetHdevmode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdatePrinterSettings
// VSWhidbey 93449: Due to the nature of PRINTDLGEX vs PRINTDLG, separate but similar methods
// are required for updating the settings from the structure utilized by the dialog.
// Take information from print dialog and put in PrinterSettings
private static void UpdatePrinterSettings(IntPtr hDevMode, IntPtr hDevNames, short copies, int flags, PrinterSettings settings, PageSettings pageSettings) {
// Mode
settings.SetHdevmode(hDevMode);
settings.SetHdevnames(hDevNames);
if (pageSettings!= null)
pageSettings.SetHdevmode(hDevMode);
//Check for Copies == 1 since we might get the Right number of Copies from hdevMode.dmCopies...
//this is Native PrintDialogs
if (settings.Copies == 1)
settings.Copies = copies;
settings.PrintRange = (PrintRange) (flags & printRangeMask);
}
示例2: UpdateSettings
private static void UpdateSettings(NativeMethods.PAGESETUPDLG data, PageSettings pageSettings,
PrinterSettings printerSettings) {
// SetHDevMode demands AllPrintingAndUnmanagedCode Permission : Since we are calling that function we should Assert the permision,
IntSecurity.AllPrintingAndUnmanagedCode.Assert();
try
{
pageSettings.SetHdevmode(data.hDevMode);
if (printerSettings != null) {
printerSettings.SetHdevmode(data.hDevMode);
printerSettings.SetHdevnames(data.hDevNames);
}
}
finally
{
CodeAccessPermission.RevertAssert();
}
Margins newMargins = new Margins();
newMargins.Left = data.marginLeft;
newMargins.Top = data.marginTop;
newMargins.Right = data.marginRight;
newMargins.Bottom = data.marginBottom;
PrinterUnit fromUnit = ((data.Flags & NativeMethods.PSD_INHUNDREDTHSOFMILLIMETERS) != 0)
? PrinterUnit.HundredthsOfAMillimeter
: PrinterUnit.ThousandthsOfAnInch;
pageSettings.Margins = PrinterUnitConvert.Convert(newMargins, fromUnit, PrinterUnit.Display);
}
示例3: OpenPrinterPropertiesDialog
public static void OpenPrinterPropertiesDialog(PrinterSettings printerSettings, IntPtr handle)
{
IntPtr hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);
IntPtr pDevMode = GlobalLock(hDevMode);
int sizeNeeded = DocumentProperties(handle, IntPtr.Zero, printerSettings.PrinterName, IntPtr.Zero, pDevMode, 0);
if (sizeNeeded < 0)
{
GlobalUnlock(hDevMode);
return;
}
IntPtr devModeData = Marshal.AllocHGlobal(sizeNeeded);
DocumentProperties(handle, IntPtr.Zero, printerSettings.PrinterName, devModeData, pDevMode, DM_IN_BUFFER | DM_OUT_BUFFER | DM_PROMPT);
GlobalUnlock(hDevMode);
printerSettings.SetHdevmode(devModeData);
printerSettings.DefaultPageSettings.SetHdevmode(devModeData);
GlobalFree(hDevMode);
Marshal.FreeHGlobal(devModeData);
}
示例4: SetDevmode
//Grabs the data in arraylist and chucks it back into memory "Crank the suckers out"
/// <summary>
/// Применение настроек принтера полученных из файла или из массива байт (mode=1 - загрузка из файла/ mode=2 - загрузка из переданного массива)
/// </summary>
/// <param name="printerSettings"></param>
/// <param name="Filename"></param>
/// /// <param name="Filename"></param>
public void SetDevmode(PrinterSettings printerSettings, int mode, String Filename, byte[] devmodearray)
{
///int mode
///1 = Load devmode structure from file
///2 = Load devmode structure from arraylist
IntPtr hDevMode = IntPtr.Zero; // a handle to our current DEVMODE
IntPtr pDevMode = IntPtr.Zero; // a pointer to our current DEVMODE
Byte[] Temparray;
try
{
var DevModeArray = devmodearray;
// Obtain the current DEVMODE position in memory
hDevMode = printerSettings.GetHdevmode(printerSettings.DefaultPageSettings);
// Obtain a lock on the handle and get an actual pointer so Windows won't move
// it around while we're futzing with it
pDevMode = GlobalLock(hDevMode);
// Overwrite our current DEVMODE in memory with the one we saved.
// They should be the same size since we haven't like upgraded the OS
// or anything.
if (mode == 1) //Load devmode structure from file
{
FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read);
Temparray = new byte[fs.Length];
fs.Read(Temparray, 0, Temparray.Length);
fs.Close();
fs.Dispose();
for (int i = 0; i < Temparray.Length; ++i)
{
Marshal.WriteByte(pDevMode, i, Temparray[i]);
}
}
if (mode == 2) //Load devmode structure from arraylist
{
for (int i = 0; i < DevModeArray.Length; ++i)
{
Marshal.WriteByte(pDevMode, i, DevModeArray[i]);
}
}
// We're done futzing
GlobalUnlock(hDevMode);
// Tell our printer settings to use the one we just overwrote
printerSettings.SetHdevmode(hDevMode);
printerSettings.DefaultPageSettings.SetHdevmode(hDevMode);
// It's copied to our printer settings, so we can free the OS-level one
GlobalFree(hDevMode);
}
catch (Exception ex)
{
if (hDevMode != IntPtr.Zero)
{
MessageBox.Show("BUGGER");
GlobalUnlock(hDevMode);
// And to boot, we don't need that DEVMODE anymore, either
GlobalFree(hDevMode);
hDevMode = IntPtr.Zero;
}
}
}