A TextBox that can only enter numbers

xiaoxiao2021-03-19  203

public class TextBoxNum: System.Windows.Forms.TextBox {public TextBoxNum () {// // TODO: Add constructor logic here //} protected override void OnKeyPress (System.Windows.Forms.KeyPressEventArgs e) {if ( E.keychar.tostring (). Length == 1) {Switch (E.KEYCHAR) {CASE '0': Case '1': Case '2': Case '3': Case '4': Case '5' : Case '6': Case '8': Case ': Case (Char) System.windows.Forms.keys.Back: // You can extend the validity of other key values ​​E.handled = false Break; Default:

// Other key values ​​are not allowed to be embedded; Break;

}} Base.onkeyPress (e);} protected override void onimemodechanged (eventargs e) {

// Shield input method this.imemode = system.windows.forms.imemode.disable; base.onimemodechanged (e);}

}

转载请注明原文地址:https://www.9cbs.com/read-130258.html

New Post(0)