Getting nice-looking widget sizing in MonoDevelop (Gtk#)

2.9k Views Asked by At

EDIT: Click here for the code.

So I'm experimenting with interface building with MonoDevelop (version 2.4). I'm trying to get used to the Gtk concept of "containers within containers". I created a vbox with two... er... boxes, put a menu on the top box, and a table on the bottom one. I set the table to have two column and five rows. On the top four rows, I put a label in the left and an entry in the right. On the bottom right cell I put a button. It looks like this:

GUIBlah Application

Here's the things I'm struggling with:

1) How do I get the table's columns NOT to be of equal width? Amusingly, when I added just the labels, and hadn't added the entry boxes yet, the left column used up only the space needed for the labels. Now it's 50/50 and it won't budge.

2) How do I get the labels to be right-aligned, so the final ":" in their texts gets nicely aligned and close to the entry boxes? I set the "Justify" property of the labels to "Right" and was seemingly ignored.

3) The action code for the "Open" and "Close" actions under the "File" menu consist on displaying a modal message box with an OK button. But pressing the OK button doesn't dismiss the message box, only closing the message box window does. The code is:

(new Gtk.MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok,
                  "Open Action")).Show();
1

There are 1 best solutions below

5
On BEST ANSWER

1) Set at least of one the Entry widgets to "expand" and "fill" horizontally.

2) Set the label's Xalign property to 1.0. Justify controls layout of wrapped text, Xalign/Yalign controls the position of the whole block within the label's area.

3) You should Destroy() the dialog after you're done with it. Alternatively you can Hide() it and re-use it. You should also look into using the dialog's Run() method - typically something like:

var dialog = new FooDialog(...);
try {
    dialog.Show();
    var response = (ResponseType) dialog.Run ();
    if (response == ResponseType.Ok) {
        //do stuff
    }
} finally {
    dialog.Destroy ();
}