How to create a numeric textbox in Silverlight?

前端 未结 11 966
礼貌的吻别
礼貌的吻别 2020-12-16 00:37

As the title says really. I\'ve had a look at inheriting from TextBox, but the only sensible override was \"OnKeyDown\", but that just gives me a key from the Key enum (with

11条回答
  •  孤城傲影
    2020-12-16 01:23

    private void Numclient_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key < Key.D0 || e.Key > Key.D9)
        {
            if (e.Key < Key.NumPad0 || e.Key > Key.NumPad9)
            {
                if (e.Key != Key.Back && e.Key != Key.Shift)
                {
                    e.Handled = true;
                }
            }
        }
    }
    

提交回复
热议问题