3

Usually, for Labels you can do something like this:

Label label = new Label ("<b>Some Text</b>") {
    UseMarkup = true
};

However, Gtk.Frame's label is just a string, not a full-fledged Label. I can't find an option to use markup. How to I enable markup, or otherwise set the label to be bold?

Matthew
  • 28,056
  • 26
  • 104
  • 170

3 Answers3

3

The label of a GtkFrame can be any widget and you can use your own GtkLabel if you wish.

ntd
  • 7,372
  • 1
  • 27
  • 44
1

Gtk.Frame has the possibility of setting any widget as "label". You can access this widget by accessing the property LabelWidget. Using this possibility, you can set a new Gtk.Label with any properties you need.

var frmExample = new Gtk.Frame();
frmExample.LabelWidget = new Gtk.Label() { Markup = "<b>Example</b>" };
this.Add( frmExample );
this.showAll();

The solution is actually simpler for the specific case of a label with markup. I've found that the Gtk.Frame already has a Gtk.Label attached, and, as you said, you can set the markup property to true.

var frmExample = new Gtk.Frame( "<b>Example</b>" );
( (Gtk.Label) this.frmExample.LabelWidget ).UseMarkup = true;
this.Add( frmExample );
this.showAll();

Hope this helps.

Baltasarq
  • 12,014
  • 3
  • 38
  • 57
  • 1
    Following your friendly style: False. The code works since I have used it tons of times. Obviously you don't know about Gtk# since you are referring to the underlying (core) Gtk+ library. Take into account that Gtk# could add behaviour or state you don't know about: a good reason for prudence. Specially in such a questionable phrase like: "If you had tested this code, you'd know it won't work." – Baltasarq Feb 23 '16 at 21:45
  • 1
    +1; I learned something new from all this :-) I'll need to check whether `gtkmm` also has a default `Label` widget, which could be very useful! I thought it just had a string but, as you noted, might've been wrongly extrapolating from GTK+, or maybe I didn't even read _that_ right ;-) – underscore_d Feb 24 '16 at 10:29
0

Not sure how it would look in C# but in plain C you could do this:

  frame = GTK_WIDGET (g_object_new (GTK_TYPE_FRAME, "label", "", NULL));
  label = gtk_label_new(_("<b>Scope</b>"));
  gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
  gtk_frame_set_label_widget (GTK_FRAME(frame), label);
Wiley
  • 506
  • 5
  • 4