I’ve been experimenting with the Mono Xwt library recently. I kind of like the idea of being able to develop once and run on any machine (don’t ask about redistributing Mono libraries, I’ve yet to learn that lesson). I hit a bit of a “speed bump” when I tried to create a dialog box with a decent amount on text in it. Searching only drew complaints about how Xwt lacks a multi-line text display. So I did a little hacking/experimenting and managed to come up with this work-around.
Working code:
public class TextDialog: Dialog { VBox layout; Button button; WidgetSpacing spacing = new WidgetSpacing(1, 1, 1, 1); public TextDialog(string title, string buttonText, string text) { Title = title; CloseRequested += OnButtonClicked; Padding = spacing; layout = new VBox(); layout.Margin = spacing; RichTextView textView = new RichTextView(); textView.LoadText(text, PlainTextFormat.Plain); textView.Sensitive = true; textView.ExpandHorizontal = true; textView.Margin = spacing; layout.PackStart(textView, true, true); button = new Button(buttonText); button.Clicked += OnButtonClicked; button.Margin = spacing; layout.PackEnd(button, false, false); layout.ExpandHorizontal = true; Content = layout; this.Show(); textView.MinWidth = button.Size.Width * 5; // hack to make the text readable } protected void OnButtonClicked(object sender, EventArgs e) { Application.Exit(); } } |
It’s not perfect, but it’s a way to get multi-line text displayed.