labelgtk#right-justified

Center/Right-justify two labels in GTK sharp


I have two labels I want to horizontally align within a window, but need one to be centered and the other to be right justified. How do I accomplish this with boxes and/or tables?


Solution

  • I ended up creating an HBox and added it to a VBox. To the HBox I added three widgets:

    var hBox = new HBox(true, 0);
    hBox.PackStart(new Label(), true, true, 0);
    hBox.PackStart(new Alignment(0.5f, 0, 0, 0) { new Label() }, true, true, 0);
    hBox.PackStart(new Alignment(1, 0, 0, 0) { new Label() }, true, true, 0);
    

    The key seemed to be homogeneous sizing (the true in the HBox constructor) and the center and right alignment widgets.