I want to create a dialog window, where the user can perform various tasks, and would like him to return from the dialog by clicking on the Cancel button with the mouse (i.e. not by hitting Enter). Therefore I do not want to use CreateDialog. However, by creating a less-specific dialog window via CreateWindow, all strings appear unformatted.
expr = Column[{
Row@{"set variable to: ", InputField["value", String]},
"Try to hit Enter in any of the dialogs: it closes #2 but not #1.",
CancelButton[]
}];
CreateWindow[DialogNotebook[expr], WindowSize -> All, WindowMargins -> {{100, Automatic}, {Automatic, Automatic}}, WindowTitle -> "1. CreateWindow & DialogNotebook"];
CreateDialog[expr, WindowTitle -> "2. CreateDialog"];

Is there any clever way to have the looks of the second dialog window, but the button-behaviour of the first one? Of course, expr here is a simple example, but it can be quite complex in reality, thus it is no option to wrap every string into Cell[string, "Text"], and every other expression into some obscure boxform.
This will stop your dialog window closing when Enter is pressed:
CreateDialog[expr, WindowTitle -> "2. CreateDialog", NotebookEventActions -> {}];
It overwrites the default dialog NotebookEventActions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With