Showing Font Selection Dialog in GTK#

核能气质少年 提交于 2019-12-11 17:58:18

问题


In MY gtk# Application im trying to show the font selection dialog.Im trying to use the following code,but the FontSelectionDialog constructor need some arguments also does the control execution wait for a font to be selected to set the string font

Can someone guide me?

Gtk.FontSelectionDialog fs = new FontSelectionDialog()
            fs.Show ();
            font=fs.FontName;

回答1:


Updated according to additional question

This should help:

FontSelectionDialog dialog = null;
try {
    dialog = new FontSelectionDialog("Choose a font");
    dialog.Run ();
    var name = dialog.FontName;
    var pattern = @"^(?<fontName>.*)\s(?<fontSize>\d+(?:\.\d+)?)$";
    var regex = new Regex(pattern);
    var match = regex.Match(name);
    if(match.Success)
    {
        var fontName = match.Groups["fontName"].Value;
        var fontSize = float.Parse(match.Groups["fontSize"].Value);
        var font = new System.Drawing.Font(fontName, fontSize);
    }
} finally {
    if (dialog != null)
        dialog.Destroy ();
}


来源:https://stackoverflow.com/questions/20511014/showing-font-selection-dialog-in-gtk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!