I am using Gtk#, but the principle is probably the same as regular GTK3. I created the default GtkApplication, and added the following lines to the scaffolding to show a message dialogue with multi-line text (50 in the example).
The problem is that when the lines are too many, the dialogue window grows beyond the screen height, so that the button below becomes invisible. Is there a way to make it show a vertical scrollbar when the message is too long, and ensure that the dialogue does not grow beyond the screen height?
Is there such a feature in the Gtk.MessageDialog
, or do I have to use a custom dialogue window?
private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("MainWindow"))
{
builder.Autoconnect(this);
DeleteEvent += Window_DeleteEvent;
_button1.Clicked += Button1_Clicked;
var lines = new List<string>();
for (int i = 0; i < 50; i++)
{
lines.Add("Line " + i);
}
var m = new Gtk.MessageDialog(this,
DialogFlags.Modal,
MessageType.Warning,
ButtonsType.Cancel,
string.Join("\r\n", lines)
);
var res = m.Run();
m.Destroy();
}
I don't think this feature exists for GtkMessageDialog
. If you want special behavior for your dialog, you should use a GtkDialog
which is more generic and allows specifying the type of widget in its "Content area". Look for the
equivalent of gtk_get_content_area
in Gtk#. This function returns a GtkBox
in which you can pack whatever widget you want. You could pack something with scrollbars inside.
Look for the "interactive dialog" in the Gtk3 demos (launch gtk3-demo
) to see an example. It is also available on the Gnome repository (in C).