转换为字体信息
有人可以帮我将这些字符串/整数转换为可用的字体吗?它不断在下面的行下面出现一条红色的波浪线:
mylabel.FONT = new Font(fname, fsize, fstyle);
而且当我尝试通过这样做设置标签前景色时:
mylabel.ForeColor = fcolor;
我的代码是:
int fcolor = Int32.Parse(match.Groups[5].Value);
string fname = match.Groups[6].Value;
int fsize = Int32.Parse(match.Groups[7].Value);
string fstyle = match.Groups[8].Value;
非常感谢
杰森
can someboody please help me convert these strings/ints into a usable font thing? it keeps coming up with a red squigly line underneith the following line:
mylabel.FONT = new Font(fname, fsize, fstyle);
and also when i try to set the labels forecolor by doing this:
mylabel.ForeColor = fcolor;
the code i have is:
int fcolor = Int32.Parse(match.Groups[5].Value);
string fname = match.Groups[6].Value;
int fsize = Int32.Parse(match.Groups[7].Value);
string fstyle = match.Groups[8].Value;
thank you very much
jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FontSize 是一个浮点数,FontStyle 是一个枚举。因此,它需要是:
获取浮动很容易......获取字体样式可能会更粘一些。如果您有一个表示“斜体”或“粗体”的字符串值,您可以使用如下所示的愚蠢简单的 EnumUtils 方法来获取枚举值:
如果没有,则会更难。但最终,您确实需要找到一种方法来转换您所拥有的任何内容 进入此:
FontStyle 是一个位标志,因此可以像这样组合值:
这方面使解析问题变得棘手。
FontSize is a float and FontStyle is an enum. Thus it would need to be:
Getting a float is easy enough... getting the font style can be a bit more sticky. If you have a string value which represents, say, "Italic" or "Bold", you can use a stupid-simple EnumUtils method like below to get the enum value:
If not, it will be harder. But ultimately, you do need to find a way to convert whatever you've got into this:
FontStyle is a bit flag, so values can be combined like so:
This aspect makes the parsing issue sticker.