c# WinForms can you get the NumericUpDown text area

后端 未结 4 1343
半阙折子戏
半阙折子戏 2021-01-16 16:09

Is it possible to get the text area of a NumericUpDown control? I\'m looking to get it\'s size so that I can mask it with a panel. I don\'t want the user to be able to edit

4条回答
  •  别那么骄傲
    2021-01-16 17:15

    If you want do disallow manual editing, you can just set ReadOnly property to true.

    updown.ReadOnly = true;
    

    If you want to disallow selecting too (I wonder why you need this), you can use reflection. I don't think there's better way, because the field upDownEdit is internal field of UpDownBase.

    FieldInfo editProp = updown.GetType().GetField("upDownEdit", BindingFlags.Instance | BindingFlags.NonPublic);
    TextBox edit = (TextBox)editProp.GetValue(updown);
    edit.Enabled = false;
    

提交回复
热议问题