[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 451
  • Last Modified:

Change printer settings

Hello,

I have a radio button list with values (8 1/2 * 11 Portrait, 11*17 Landscape, etc.. ). When the user selects any one of the value and click 'Print' button, it should change the printer settings accordingly and print the page. How can I do this?

Thanks
Praveen
0
praveenuni
Asked:
praveenuni
  • 5
  • 4
1 Solution
 
cyberdevil67Commented:
Try this


   .NET Framework Class Library  

PageSettings.PaperSize PropertySee Also
PageSettings Class | PageSettings Members | System.Drawing.Printing Namespace | PaperSize | PaperSize.Height | PaperSize.Kind | PaperSize.Width | PageSettings Members (Visual J# Syntax) | Managed Extensions for C++ Programming
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Language
C#

C++

JScript

Visual Basic

Show All
Gets or sets the paper size for the page.

[Visual Basic]
Public Property PaperSize As PaperSize

[C#]
public PaperSize PaperSize {get; set;}

[C++]
public: __property PaperSize* get_PaperSize();
public: __property void set_PaperSize(PaperSize*);

[JScript]
public function get PaperSize() : PaperSize;
public function set PaperSize(PaperSize);

Property Value
A PaperSize that represents the size of the paper. Defaults to the printer's default paper size.

Exceptions
Exception Type Condition
InvalidPrinterException The printer named in the PrinterSettings.PrinterName property does not exist or there is no default printer installed.

Remarks
An instance of PaperSize represents the size of the paper through the PaperSize.Kind property, which contains one of the PaperKind values.

Set the PaperSize property for the page to a valid PaperSize, available through the PrinterSettings.PaperSizes collection.

See the PaperSize constructor to find out how you can specify a custom paper size.

Example
[Visual Basic, C#, C++] The following example sets three properties for the document's default page, including the paper size based upon the size selected in the comboPaperSize combo box, and then prints the document using the Print method. The example assumes that a PrintDocument variable named printDoc exists and that the specific combo boxes exists.

[Visual Basic]
Private Sub MyButtonPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButtonPrint.Click

    ' Set the paper size based upon the selection in the combo box.
    If comboPaperSize.SelectedIndex <> -1 Then
        printDoc.DefaultPageSettings.PaperSize = _
        printDoc.PrinterSettings.PaperSizes.Item(comboPaperSize.SelectedIndex)
    End If

    ' Set the paper source based upon the selection in the combo box.
    If comboPaperSource.SelectedIndex <> -1 Then
        printDoc.DefaultPageSettings.PaperSource = _
        printDoc.PrinterSettings.PaperSources.Item(comboPaperSource.SelectedIndex)
    End If

    ' Set the printer resolution based upon the selection in the combo box.
    If comboPrintResolution.SelectedIndex <> -1 Then
        printDoc.DefaultPageSettings.PrinterResolution = _
        printDoc.PrinterSettings.PrinterResolutions.Item(comboPrintResolution.SelectedIndex)
    End If

    ' Print the document with the specified paper size and source.
    printDoc.Print()

End Sub

[C#]
private void MyButtonPrint_Click(object sender, System.EventArgs e)
{
    // Set the paper size based upon the selection in the combo box.
    if (comboPaperSize.SelectedIndex != -1) {
        printDoc.DefaultPageSettings.PaperSize =
            printDoc.PrinterSettings.PaperSizes[comboPaperSize.SelectedIndex];
    }

    // Set the paper source based upon the selection in the combo box.
    if (comboPaperSource.SelectedIndex != -1) {
        printDoc.DefaultPageSettings.PaperSource =
            printDoc.PrinterSettings.PaperSources[comboPaperSource.SelectedIndex];
    }
   
    // Set the printer resolution based upon the selection in the combo box.
    if (comboPrintResolution.SelectedIndex != -1)
    {
        printDoc.DefaultPageSettings.PrinterResolution=
            printDoc.PrinterSettings.PrinterResolutions[comboPrintResolution.SelectedIndex];
    }

    // Print the document with the specified paper size, source, and print resolution.
    printDoc.Print();
}

[C++]
private:
   void MyButtonPrint_Click(Object* sender, System::EventArgs* e) {
      // Set the paper size based upon the selection in the combo box.
      if (comboPaperSize->SelectedIndex != -1) {
         printDoc->DefaultPageSettings->PaperSize =
            printDoc->PrinterSettings->PaperSizes->Item[comboPaperSize->SelectedIndex];
      }

      // Set the paper source based upon the selection in the combo box.
      if (comboPaperSource->SelectedIndex != -1) {
         printDoc->DefaultPageSettings->PaperSource =
            printDoc->PrinterSettings->PaperSources->Item[comboPaperSource->SelectedIndex];
      }

      // Set the printer resolution based upon the selection in the combo box.
      if (comboPrintResolution->SelectedIndex != -1) {
         printDoc->DefaultPageSettings->PrinterResolution=
            printDoc->PrinterSettings->PrinterResolutions->Item[comboPrintResolution->SelectedIndex];
      }

      // Print the document with the specified paper size, source, and print resolution.
      printDoc->Print();
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button  in the upper-left corner of the page.

Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also
PageSettings Class | PageSettings Members | System.Drawing.Printing Namespace | PaperSize | PaperSize.Height | PaperSize.Kind | PaperSize.Width | PageSettings Members (Visual J# Syntax) | Managed Extensions for C++ Programming


Syntax based on .NET Framework version 1.1.
Documentation version 1.1.0.


--------------------------------------------------------------------------------

Send comments on this topic.

© 2001-2002 Microsoft Corporation. All rights reserved.

0
 
praveenuniAuthor Commented:
Thanks for the information. I have one question.. how to declare printdoc.


0
 
cyberdevil67Commented:
I pulled that from the MSDN so I am not 100% sure

try this

        Printing thisPrinter = new Printing

Which is in the System.Data.Printing and has properites that can be read or set for papersizes as well.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
praveenuniAuthor Commented:
I tried the above code in C#, but I'm unable to print anything. Anu suggestions?
0
 
cyberdevil67Commented:
We use that to get the default printer, so I would assume that you could use that to set the page size.

we actually use that to print CR reports, but I don't see why you can't use the normal PrintDocument from the toolbox.
0
 
praveenuniAuthor Commented:
The application I'm working on (asp.net app with C# as code-behind), requires the user to select all the printer settings and print it from app itself. Could you please tell me with a small example on how to print the page from app itself with 'landscape' as the orientation?

Thanks
0
 
cyberdevil67Commented:
Sorry that code will only work server, or as a standalone application. What your asking for is ASP.Net which means you are trying to print to the clients printer can't do that.
0
 
praveenuniAuthor Commented:
Oh ok .. Is there anyway I can print to the client printer from asp.net (with print settings).

Thanks
0
 
cyberdevil67Commented:
No

The only way to print anything would be to create a pdf in the size you want, or use crystal reports or some form of document creation on the server to be delivered to the client in the format you want.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now