简体   繁体   中英

How do I make a Gtk.Frame's label bold?

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?

GtkFrame的标签可以是任何小部件 ,如果您愿意,您可以使用自己的GtkLabel。

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.

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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM