简体   繁体   English

如何使Gtk.Frame的标签变粗?

[英]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. 但是,Gtk.Frame的标签只是一个字符串,而不是一个完整的标签。 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". Gtk.Frame可以将任何小部件设置为“标签”。 You can access this widget by accessing the property LabelWidget . 您可以通过访问LabelWidget属性来访问此小部件。 Using this possibility, you can set a new Gtk.Label with any properties you need. 使用这种可能性,您可以使用您需要的任何属性设置新的Gtk.Label

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 . 我发现Gtk.Frame已经附加了Gtk.Label ,正如你所说,你可以将markup属性设置为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: 不确定它在C#中的外观如何,但在普通C中你可以这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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