修改后的代码如下,记录在这里以备学习
namespace TypeYourTitle
{
public class TypeYourTitle:Window
{
[STAThread]
public static void Main()
{
Application app = new Application();
TypeYourTitle tyt = new TypeYourTitle();
tyt.Background=new SolidColorBrush(Color.FromRgb(0, 255, 255));//背景色
tyt.ResizeMode = ResizeMode.CanResizeWithGrip; //改变大小模式,CanResizeWithGrip窗体右下角有个小手
app.Run( tyt);
//原书中例子run调用自身进行运行 tyt对象是我修改背景和大小模式自己增加的
//app.Run(new TypeYourTitle());
}
protected override void OnTextInput(TextCompositionEventArgs e)
{
base.OnTextInput(e);
if (e.Text == "/b" && Title.Length > 0)
{
Title = Title.Substring(0, Title.Length - 1);
}
else if (e.Text.Length > 0 && !Char.IsControl(e.Text[0]))
{
Title += e.Text;
}
}
}
}