在电灯开关文本框中设置字体 [英] Setting font in light switch textboxes

查看:91
本文介绍了在电灯开关文本框中设置字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在LightSwitch中设置文本框的字体设置.我不确定我的代码是否有问题,或者这根本不可能.

I am trying to set set the font of a TextBox in LightSwitch. I am not sure if there is a problem with my code, or if this just isn't possible.

代码已执行,并且我已逐步完成以确保其已执行,并且可以到达并执行所有代码,但是屏幕上的控件没有更改.

The code executes, and I have stepped through it to make sure it executes, and all code is reached and executed, but there is not change to the controls on the screen.

我的代码是:

private void SetMono(string controlName)
        {
            var ctrl = this.FindControl(controlName);
            if (ctrl != null)
            {
                ctrl.ControlAvailable += (s, e) =>
                {
                    if (e.Control is TextBox)  // I put break point here to test.                        {
                        var tb = (TextBox)e.Control;
                        var ff = new System.Windows.Media.FontFamily("courierNew,courier,monospace");
                        tb.FontFamily = ff;
                    }
                };
            }
        }

我做错什么了吗?

(我正在使用VS 2013)

(I am using VS 2013)

推荐答案

问题出在我的FontFamily.我找不到有关应如何命名字体家族的太多信息,但是"Consolas" 确实起作用.

The problem was my FontFamily. I could not find to much information on how the Font Family should be named, but "Consolas" did work.

最终密码:

private void SetMono(string controlName)
        {
            var ctrl = this.FindControl(controlName);
            if (ctrl != null)
            {
                ctrl.ControlAvailable += (s, e) =>
                {
                    if (e.Control is TextBox)
                    {
                        var tb = (TextBox)e.Control;
                        tb.FontFamily = new System.Windows.Media.FontFamily("Consolas");
                    }
                };
            }
        }

这篇关于在电灯开关文本框中设置字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆