I w开发者_C百科ant 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.
Another option:
expr = Style[
Column[{Row@{"set variable to: ", InputField["value", String]},
"Try to hit Enter in any of the dialogs: it closes #2 but not \
#1.", CancelButton[]}], ShowStringCharacters -> False];
Perhaps using TextCell
:
expr = Column[{Row@{TextCell@"set variable to: ",
InputField["value", String]},
TextCell@"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"]
Edit
Use
TextCell@Style[" ... blah blah ...", style_opt ]
for formatting.
There are a number of ways to do this, and other folks have posted two good ones, but in my opinion the easiest approach is to set the BaseStyle
of the Column
expression to match the base style of the dialog, and then use CreateWindow
. The style in question is "Panel"
, so this gets you the result you want:
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[]}, BaseStyle -> "Panel"];
CreateWindow[DialogNotebook[expr], WindowSize -> All,
WindowMargins -> {{100, Automatic}, {Automatic, Automatic}},
WindowTitle -> "1. CreateWindow & DialogNotebook"];
精彩评论