static int QueryFull(bool useErrorColors, int width, int height, ustring title, ustring message, params ustring [] buttons) { const int defaultWidth = 30; int textWidth = Label.MaxWidth(message, width); int textHeight = message.Count(ustring.Make('\n')) + 1; int msgboxHeight = Math.Max(1, textHeight) + 4; // textHeight + (top + top padding + buttons + bottom) // Create button array for Dialog int count = 0; List <Button> buttonList = new List <Button> (); foreach (var s in buttons) { var b = new Button(s); if (count == 0) { b.IsDefault = true; } buttonList.Add(b); count++; } // Create Dialog (retain backwards compat by supporting specifying height/width) Dialog d; if (width == 0 & height == 0) { d = new Dialog(title, buttonList.ToArray()); d.Height = msgboxHeight; } else { d = new Dialog(title, Math.Max(width, textWidth) + 4, height, buttonList.ToArray()); } if (useErrorColors) { d.ColorScheme = Colors.Error; } if (message != null) { var l = new Label(textWidth > width ? 0 : (width - 4 - textWidth) / 2, 1, message); l.LayoutStyle = LayoutStyle.Computed; l.TextAlignment = TextAlignment.Centered; l.X = Pos.Center(); l.Y = Pos.Center(); l.Width = Dim.Fill(2); l.Height = Dim.Fill(2); d.Add(l); } // Dynamically size Width int msgboxWidth = Math.Max(defaultWidth, Math.Max(title.Length + 8, Math.Max(textWidth + 4, d.GetButtonsWidth()) + 8)); // textWidth + (left + padding + padding + right) d.Width = msgboxWidth; // Setup actions int clicked = -1; for (int n = 0; n < buttonList.Count; n++) { int buttonId = n; buttonList [n].Clicked += () => { clicked = buttonId; Application.RequestStop(); }; } Application.Run(d); return(clicked); }