Is it possible to display the WinForms “font picker” dialog non-modally? Or is there another font picker other than the standard one that can be used non-modally?
Our application has many windows, and users who frequently need to interrupt what they are doing and switch to another window to look at something. If they use a taskbar button to switch windows, this tends to lead to “buried dialog” scenarios with modal dialogs, where the UI is unresponsive, but it isn’t immediately apparent why, because the modal dialog that has captured the focus is behind another window.
The key feature of the behavior of
FontDialoghere is not the parent (owner) relationship, but fact that you can only use it by callingShowDialog, and there is no apparent way to do that without blocking the GUI thread.Fortunately, there is a way around that problem. I used a
BackgroundWorkerto shunt the call toShowDialogonto a worker thread, allowing the GUI thread to proceed. The asyncFontDialogwrapper class looks like this:[Note that you need to hide the parent window handle inside the
WindowWrapperinstance to keep the runtime from raising a cross-thread exception.]The
EventArgsclass looks like this:…and you use it like this:
Where
ParentFormis theWindows.Forminstance to which you want to tie the dialog. The resulting dialog will be modal with respect to the parent (i.e. you will not be able to do anything with the parent without first dismissing the dialog), but the rest of the appliation’s UI will work normally.