Home » WPF

Advanced Printer Properties Dialog in WPF

I'm trying to get the advanced printer properties dialog to display on the push of a button.  It should display the same thing as the Preferences button on the PrintDialog.ShowDialog window.  Is there a supplied class to do this in the .NET Framework?  If not, how is this done considering the Window API wants a DEVMODE and WPF printing uses a PrintTicket?  I seen examples of how to do this using Windows Forms, but haven't seen any examples for getting this same functionality in WPF.  Which is why I'm thinking I'm missing something.

Any help would be appreciated


5 Answers Found


Answer 1

It is the same as in WindowsForms.....

You need to add the referance System.Windows.Forms

and than


PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click


Dim dlg AsNew System.Windows.Forms.PrintDialog





Answer 2

I'm looking to display the advanced printer settings, not the printer dialog.  Run your code above and hit the preferences button on the window that is displayed.  That is the window I want/need without having to get there from the print dialog.

Answer 3

I think I may be making some headway, but I need some assistance on one issue.  The print settings are flowing out of the dialog, but not in.  For example, if the PrintTicket is set to Landscape when entering the dialog, the dialog still shows Portrait.  But if the orientation is changed while it is open, it does show this change on the retrieved PrintTicket.  How do I fix this one issue?

EDIT:  Had a ref keyword on the pDevModeInput parameter.  Removed it and it works as expected.  So below is a working solution.  If there is a better way or if I'm doing something incorrectly, please let me know.

		[DllImport("winspool.Drv", EntryPoint = "DocumentPropertiesW", SetLastError = true,
			 ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
		static extern int DocumentProperties(IntPtr hwnd, IntPtr hPrinter,
			[MarshalAs(UnmanagedType.LPWStr)] string pDeviceName,
			IntPtr pDevModeOutput, IntPtr pDevModeInput, int fMode);

			PrintTicketConverter ptc = new PrintTicketConverter(SelectedPrintQueue.Name, SelectedPrintQueue.ClientPrintSchemaVersion);
			IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle;

			byte[] myDevMode = ptc.ConvertPrintTicketToDevMode(SelectedPrintQueuePrintTicket, BaseDevModeType.UserDefault);
			GCHandle pinnedDevMode = GCHandle.Alloc(myDevMode, GCHandleType.Pinned);
			IntPtr pDevMode = pinnedDevMode.AddrOfPinnedObject();
			DocumentProperties(mainWindowPtr, IntPtr.Zero, SelectedPrintQueue.Name, pDevMode, pDevMode, 14);
			SelectedPrintQueuePrintTicket = ptc.ConvertDevModeToPrintTicket(myDevMode);

Answer 4

Be careful. For network printers you will need to use the SelectedPrintQueuePrintTicket.FullName property instead of the Name property!

Answer 5

Thank you,

I was trying to do this myself and you saved me a lot of trouble.

I especially like your usage of pinning the GCHandle as I was going the route of Marshal.AllocHGlobal, with the code looking a lot less clean and unnecessary copying.


How do I get at and invoke the properties dialog supplied by the manufactured?  I have search this many times and found that most of the posts contain solutions that the original poster claims don't work  The standard PrintProperties class does not handle a lot of printers who have specifictsks, eg a printer designed to pint on the face odf CD/DVD.  I have found exampls of how do this in VB6, but every examply I find for the versions of VB Basic after thet have comments that the solution provided did not persist the user chnges.  Bow, come on, there has to be a way of displaying and persisting the user choises the dialog bog provided by the printer manufacturer!

I have a SharePoint site in which I have a photo database (picture library). The photographs are of different types of signs and each have metadata stored about them (for example, what type of materials were used, if the photo is interior or exterior, what type of sign it is, etc. Almost all of these columns are multiple selection fields). I want to be able to search this library by each of these metadata fields in the advanced search as a property restriction. (so look for an exterior monument sign for example).

I have been doing research and know that I need to perform a crawl of this metadata and then create a managed property. I have not been able to find a good step by step description of how to do this and I am looking for some help. I dont have a strong coding background or much familiarity with the sharepoint central administration site. Please help!


I am learning MFC , the compiler is vs 2008.

Now i have a question about the activex controls.

I have made an clock activex control using the MFC Activex Control  Wizard .

Then i add two stock properties , a custom method and a custom event to it.

These stock properties are ForeColor and BackColor.  Because i want to modify the backcolor and  forecolor in the property page of the activex control ,so i add this here:

BEGIN_PROPPAGEIDS(Cv18e1_ClockCtrl, 2)

and in the body of OnDraw(), i add these :

void Cv18e1_ClockCtrl::OnDraw(
   CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
 if (!pdc)

 // TODO: Replace the following code with your own drawing code.
 //pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
 CBrush brush(TranslateColor(GetBackColor()));
 pdc->FillRect(rcBounds, &brush);
 CTime time = CTime::GetCurrentTime();
 if(0 == time.GetSecond())
 CString str = time.Format(_T("%H:%M:%S"));
 pdc->TextOut(0, 0, str);

At first i test it in the tstcon container, everything is fine.

1.But when i test it in a windows form applition in VB, and modify the BackColor and ForeColor in the property page of the activex control, it doesn't work, the backcolor and forecolor doesn't change(when i modify these in the property page privided by VB, it works and the control's backcolor and fore color change).

2.It is the same situation when i test it in a MFC Application based on dialog

3.And thereis another question, in the MFC Application based on dialog, i add the activex control by the wizard, and the wizard create a class for it .But in the class view, i can't find these two method: SetBackColor(OLE_COLOR),  SetForeColor(OLE_COLOR). Because i have add these two stock properties : BackColor , ForeColor, why i can't find these two method? Now i want to use these two method ,how?

In VC 6.0 , i can find these two method , and has no problem , why it is so hard in VS 2008? Anyone can help me?



I'm writting a program in C++ using VisualStudio 2010 and the sole purpose of it is to fill out a single form. It took me about 3 hours of searching through the help(?) system to finally find sample code in the Spiro sample that let me default the printer to landscape mode. In the process I remember seeing something about suppressing the print dialog box but it wasn't related to the method used in Spiro to control the print mode. Spiro uses the PRINTDLG structure to set things but I don't see anything in it that allows display of the dialog box itself to be bypassed.

Any suggestions on how I can skip it?



I notice there is no printer dialog box available in visual studio 2008 when writing an application to run on a device using CE 6.0

Does this mean you cannot print under CE6.0?

Hi guys,
I'm new to wpf, currently doing my first real world steps ;-)
I heard about the truely powerful databinding in wpf and have some questions about it:
I have a ViewModel --> TerminalViewModel
This view model exposes a property with a IEnumerable<UserComputer>.
On my view where i want to use this view model is a grid. I want that there is one button per userComputer in my view. That means if in my UserComputer collection are 10 usercomputer objects i would like to have 10 buttons on my form. Is this possible over databinding or is this edge of wpf databinding ? ;-)
Thank you for any help in advance,
kind regards


Hi Team,

I need your valuable inputs,  for one of the problem I am facing . Actually I am trying to implement the "Pages Per Sheet" option in my Application's Print Dialog . So I am trying to change the Defualt PrintTicket by changing the "PagesPerSheet" property of the PrintTicket . I am using the below code to perform the modification of the defualt PrintTicket.

PrintTicket delTicket = new PrintTicket();

delTicket.PagesPerSheet = 4;

System.Printing.ValidationResult Res = LocalPrintServer.GetDefualtPrintQueue().MergeAndValidatePrintTicket(LocalPrintServer.GetDefualtPrintQueue().UserPrintTicket,delTicket);

Although I am not getting any error in executing the above statement . Default property "PagesPerSheet" is not getting modified ,its retaining the same old value as NULL.

Is this the correct way to perform modification on PrintTicket ,please do correct me if am going wrong way.

I would be really grateful for any inputs or suggestion.




Hi, All!

I have a problem with getting values from resources. In advanced search i trying to modify web-part. under properties i see default xml with some attributes, like:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<LangDef DisplayName="English" LangID="en"/>
<Language LangRef="en"/>
<PropertyDef Name="Path" DataType="integer" DisplayName="URL"/>

well i tried (for test) change "DisplayName" to some value from resource (which dynamic modified when user change display language) with next code:

<LangDef DisplayName="$Resources:core,Company" LangID="en"/>

I see, when refresh page, near checkbox $Resources:core,Company instead only Company (from resources). Quotation, marks semicolon - nothing helps me.

For last i tried to get value with xsl in next code:


 <xsl:value-of select="concat('&lt;LangDef DisplayName=&quot;','nmfgh','&quot; LangID=&quot;en&quot; /&gt;')" disable-output-escaping="yes"/>


and saw nothing.

Next i just trying to copy and paste same what was default in properties and save that. and values have become static: If i did it in english, on other langs i can see only english values, if in other langs, in english i see only from other.

Can anyone helps me?


Hi, I am developing an application to do bulk printing. The application has to print 100s pages for each hour. I am trying to fetch papers from different trays and print accordingly. I was aiming to develop web application but was not able to do so. So i went for windows application and done with axW


 here i don't have an option to get printer information. Or option to push to a particular printer. I tried to use WebBrowser control too. but couldn't find an option to achieve the above. 

 Any Suggestion?



I want to customize the advanced search webpart adding properties which are managed metadata.

How to do so?

I have Narrow the search...  section in advance serch page but I don't want Add property restrictions... on the page; i guess this comes along Result type property.
I have removed all the peroperties of the documents available in the Result type(doc, xls, PDF) from the xml but still it shows Add property restrictions with blank drop downs.
Need urgent help to remove this......
Just in case you wana know!!! I am using Search server 2008 Express edition.


I am writing a new WPF application that creates some visual elements and then trying to print them on a datacard printer. I am successfully printing using the System.Printing classes in WPF as follows:


Dim Pd As PrintDialog = New PrintDialog()
Dim Ps = New LocalPrintServer()
Dim PrintQueue = New PrintQueue(Ps, "Datacard Printer")
Pd.PrintQueue = PrintQueue
Pd.PrintVisual(Me.Grid1, "Print Job 1")  'this prints out perfectly


The problem is that the Datacard printer has an SDK that you can use to write to the Magstrip on the back of the card.  I have a working example using the PrintPageEventArgs in System.Drawing.Printing but I cannot find any close matches for the WPF world.  Here is that code:


PrivateSub PrintPage(ByVal sender asObject, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
  '...' Obtain the device context for this printer
  deviceContext = e.Graphics.GetHdc().ToInt32()

  '... device context is used in SDK to write to magstrip

  e.Graphics.ReleaseHdc(New IntPtr(deviceContext))
So, my question is:  

How can I print my existing markup (XAML) using System.Drawing.Printing
Are there events in the System.Printing to talk to the SDK and getting the Int32 deviceContext?


Bryan Brannon

Hi, developers!

Whether probably on the basis of WPF to create animation of flaring fire, shiver a working window, a fog, solar rays and other difficult components??
If yes, as??




I've been trying to get a WPF Window to pop up as a Modal Dialog from a Windows Form application.

Much of what I've read indicates that I should use WindowInteropHelper.

Like this example. http://social.msdn.microsoft.com/forums/en-US/wpf/thread/4997db56-3235-4584-9365-9c69957f9f07/?prof=required

However, it does not work!

Specifically, it does not open as modal.  The parent window does not become disabled, and does not dissallow the user to click on it and interact with it even though the Dialog is open.

Replicating my issue:

1. Create a new application of type "Windows Forms Application" of the name "Window-Dialog"
2. Add a new project of type "WPF Application".  leave as default name.
3. Set the "Start Up Projects" as Multiple.  "Window-Dialog" to Start, and "WpfApplication1" to Start.
4. Open the Wpf applications "App.xml"
5. Add a Startup event handler, and remove the StartupUri.
6. Open the "App.xaml.cs"
7. Inside that file add the following code:

privatevoid Application_Startup(object sender, StartupEventArgs e)
Process[] procs = Process.GetProcessesByName("Window-Dialog.vshost");
IntPtr parentHandle = procs[0].MainWindowHandle;
Window1 dialog = new Window1();
WindowInteropHelper helper = new WindowInteropHelper(dialog);
helper.Owner = parentHandle;


 8. Run in Debug.   (If you want to run without debug, you must remove the ".vshost" from the GetProcessesByName call.


Results are two windows (Form1 and Window1).  One which is bound to the other as child (Window1) and parent (Form1).  But they aren't modal.  The parent (Form1) is not disabled and the user is not prevented from clicking on it and interacting with it.

Now, how do I make this a proper Modal Dialog without adding any code to the Windows Forms application (Form1)?

Is there some API I have to call to disable the parent Window whilst the WPF Window is open?



I have encountered a very easily reproduced and exceedingly frustrating bug in WPF when using "nested" dialogs (i.e. windows "owned" by the window that opens them).  Here  is a quick description of a situation that causes the problem:  

MainAppWindow opens WindowA modelessly.  WindowA is owned by MainAppWindow.

WindowA opens WindowB modelessly (or modally, doesn't see to matter).  WindowB is owned by WindowA.

Close WindowB - everything is as expected: WindowA is on top of MainAppWindow and app is in foreground of desktop.

Close WindowA - WindowA closes but MainAppWindow is dropped to background of desktop (i.e. behind any other open applications).

The following simple application demonstrates the problem.  Just click construct 2 nested dialogs them close them in reverse order.  You will need to have another application like notepad in the background so that you can see the WPF app main window get dropped behind it.

To Reproduce:

   - create a new WPF application in Visual Studio (I'm using 2008, sp1) and copy/paste the following code for the Window1.xaml and Window1.xaml.cs files.  I have been able to reproduce this issue on XP, Win7 and Vista.


<Window x:Class="OwnedWindowZOrderIssue.Window1"



    Title="Window1" Height="300" Width="300">


      <Button x:Name="mNewWindowButton" Content="New Owned Window" 

              HorizontalAlignment="Center" VerticalAlignment="Center" />



using System.Windows;


namespace OwnedWindowZOrderIssue


   /// <summary>

   /// Interaction logic for Window1.xaml

   /// </summary>

   public partial class Window1 : Window


      public Window1()



         mNewWindowButton.Click += new RoutedEventHandler(mNewWindowButton_Click);



      void mNewWindowButton_Click(object sender, RoutedEventArgs e)


         Window1 newWnd = new Window1();

         newWnd.Owner = this;






Hopefully someone has a clue....

My application displays WPF Window as a modal dialog box. The dialog box has a few child user controls, one of which has combo box. When the user clicks this combo box to select... the whole dialog disappears except of the innards of the combo box. So the user only sees the list box of the combo box.

Here are the details I got from the  client: The window itself is launched from non WPF application (Lotus Notes). This happens only on a few machines. The OS is Windows XP SP3. There is no issue with the parent handle, windows owner, etc...

I've seen this behavior during the development phase, only when running under a debugger. 









Which open file dialog should be used for a wpf application

that should run on xp, vista and 7?


I'm trying to create a generic dialog in WPF using the MVVM pattern. The dialog's return value needs to be generic so it can return anything. In this case I want to return an instance of my DialogOptions class.

First, I created a DialogBase class that has a dependency property for the return value: 

using System;
using System.Windows;

namespace OutputCompare
  public class _DialogBase<T> : Window where T : new()
    public static readonly DependencyProperty RetValDP = DependencyProperty.Register("RetVal", typeof(T), typeof(_DialogBase<T>), new FrameworkPropertyMetadata());
    public T RetVal
      get { return (T)GetValue(RetValDP); }
        SetValue(RetValDP, value);

    public _DialogBase()
      RetVal = new T();
 Next I create a dialog based off it
<src:_DialogBase x:Class="OutputCompare.LoadDialog"
         RetVal="{Binding Options, Mode=TwoWay}">


public partial class LoadDialog : _DialogBase<DialogOptions>
  public LoadDialog() : base()
    DataContext = new LoadOptionsViewModel();

And finally my ViewModel
using System;
using GalaSoft.MvvmLight;

namespace OutputCompare
  public class LoadOptionsViewModel : ViewModelBase
    private DialogOptions _Options = new DialogOptions();
    public DialogOptions Options 
      get { return _Options; }
        _Options = value;

    public LoadOptionsViewModel()
      _Options.Name = "John Smith";
I'm running it like this
LoadDialog dialog = new LoadDialog();

var x = dialog.RetVal;
It compiles fine, but crashes at runtime. I think it's crashing because XAML is trying to bind to the Options property before the data context is set


bizarely strange. i just want to open a WPF window dialog from my main window and have it open at the center of my main application. But it seems not working despite using the FormStartPosition.

I am using .NET3.5. anyone with the same issue?




Hi All.

Could you suggest solution for the next issue.

We're developing an AddIn for MS PowerPoint 2010/2010 using .NET 4.0 and WPF.

While displaying the dialog it is being unexpected hidden when mouse is over same control like CheckBox, Hyperlinc or Close button (X) of the dialog.

This issue is very unstable so I can't give you any case describes it. Specified behavior differs from run to run so different controls raise this behavior.

What thing is at the bottom of such behavior?

Additional questions are being applauded.

Thank you in advance.




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure