Home > Net >  Printersettings gives some printer setup options, for some advanced printers, print the properties d
Printersettings gives some printer setup options, for some advanced printers, print the properties d

Time:09-27

Printersettings gives some printer setup options, for some advanced printers, print the properties dialog box there are many types of the printer to print configuration, the configuration can be print properties dialog box is configured,

Question: how to use c # program to configure these attributes?
Such as: (1) a piece of paper to print more pages, a page or two, a three page, a four pages, a six pages, a piece of eight pages, a nine pages; (2) brochure; (3) cross border lines; (4) the staplers,

CodePudding user response:

 
[System. The Runtime. InteropServices. DllImport (" winspool. DRV SetLastError=true)]
Public extern static int OpenPrinter (string pPrinterName, ref IntPtr hPrinter, ref IntPtr pDefault);

[System. The Runtime. InteropServices. DllImport (" winspool. DRV SetLastError=true)]
Public extern static int DocumentProperties (IntPtr hWnd, IntPtr hPrinter, string pDeviceName, ref IntPtr pDevModeOutput, ref IntPtr pDevModeInput, int fMode);

[System. The Runtime. InteropServices. DllImport (" winspool. DRV SetLastError=true)]
Public static extern int ClosePrinter (IntPtr phPrinter);

Private const int DM_PROMPT=4;

Private void PrinterAttrib_Click (object sender, EventArgs e)
{
String printerName=Input_Printer. TextBox. Text;

If (printerName!=null & amp; & PrinterName. Length & gt; 0)
{
IntPtr pPrinter=IntPtr. Zero;
IntPtr pDevModeOutput=IntPtr. Zero;
IntPtr pDevModeInput=IntPtr. Zero;
IntPtr nullPointer=IntPtr. Zero;

OpenPrinter (printerName, ref pPrinter, ref nullPointer);

Int iNeeded=DocumentProperties (print_Form. _formObject. Handle, pPrinter, printerName, ref pDevModeOutput, ref pDevModeInput, 0).
PDevModeOutput=System. The Runtime. InteropServices. Marshal. AllocHGlobal (iNeeded);
DocumentProperties (print_Form. _formObject. Handle, pPrinter printerName, ref pDevModeOutput, ref pDevModeInput, DM_PROMPT);
ClosePrinter (pPrinter);
}
}

CodePudding user response:

Change the
String printerName="printer name";

CodePudding user response:

reference 1st floor desperaso response:
 
[System. The Runtime. InteropServices. DllImport (" winspool. DRV SetLastError=true)]
Public extern static int OpenPrinter (string pPrinterName, ref IntPtr hPrinter, ref IntPtr pDefault);

[System. The Runtime. InteropServices. DllImport (" winspool. DRV SetLastError=true)]
Public extern static int DocumentProperties (IntPtr hWnd, IntPtr hPrinter, string pDeviceName, ref IntPtr pDevModeOutput, ref IntPtr pDevModeInput, int fMode);

[System. The Runtime. InteropServices. DllImport (" winspool. DRV SetLastError=true)]
Public static extern int ClosePrinter (IntPtr phPrinter);

Private const int DM_PROMPT=4;

Private void PrinterAttrib_Click (object sender, EventArgs e)
{
String printerName=Input_Printer. TextBox. Text;

If (printerName!=null & amp; & PrinterName. Length & gt; 0)
{
IntPtr pPrinter=IntPtr. Zero;
IntPtr pDevModeOutput=IntPtr. Zero;
IntPtr pDevModeInput=IntPtr. Zero;
IntPtr nullPointer=IntPtr. Zero;

OpenPrinter (printerName, ref pPrinter, ref nullPointer);

Int iNeeded=DocumentProperties (print_Form. _formObject. Handle, pPrinter, printerName, ref pDevModeOutput, ref pDevModeInput, 0).
PDevModeOutput=System. The Runtime. InteropServices. Marshal. AllocHGlobal (iNeeded);
DocumentProperties (print_Form. _formObject. Handle, pPrinter printerName, ref pDevModeOutput, ref pDevModeInput, DM_PROMPT);
ClosePrinter (pPrinter);
}
}

====================
Ask, is your print_Form should form is, the _formObject is what?

CodePudding user response:

refer to the second floor desperaso response:
change under
String printerName="printer name";

How much do you QQ, let's contact QQ, I QQ318986462, thank you

CodePudding user response:

reference Olivia teacher reply: 3/f
/
====================
Ask, is your print_Form should form is, the _formObject is what?


Sorry ah, DocumentProperties (print_Form. _formObject. Handle, pPrinter, printerName, ref pDevModeOutput, ref pDevModeInput, DM_PROMPT);
Is a form. Handle

Directly program, temporary didn't change good

CodePudding user response:

reference 5 floor desperaso reply:
Quote: xiao lu teacher reference 3 floor response:


====================
Ask, is your print_Form should form is, the _formObject is what?


Sorry ah, DocumentProperties (print_Form. _formObject. Handle, pPrinter, printerName, ref pDevModeOutput, ref pDevModeInput, DM_PROMPT);
Is a form. Handle

Directly program, temporary didn't change good

Print_Form _formObject is form name, why after my name into the form, or an error? Another you PrinterAttrib_Click is a button control to trigger event
  •  Tags:  
  • C#
  • Related