C# NumericUpDown 控件正整数输入控制

news/2024/5/1 13:26:42

用到了控件的 KeyPress 和 KeyUp事件。

KeyPress 中控制输入“点、空格,负号”;

KeyUp 中防止删空,以及防止输入超过最大值或最小值 。

        private void nudStart_KeyPress(object sender, KeyPressEventArgs e){numericUpDownKeyPress(sender, e);}private void nudStart_KeyUp(object sender, KeyEventArgs e){numericUpDownKeyUp(nudStart, sender, e);}private void numericUpDownKeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar == '.'){e.Handled = true;}else if (e.KeyChar == '-'){e.Handled = true;}else if (e.KeyChar == ' '){e.Handled = true;}}private void numericUpDownKeyUp(NumericUpDown numericUpDown, object sender, KeyEventArgs e){UpDownBase UpDowns = (UpDownBase)numericUpDown;if (UpDowns.Text == ""){numericUpDown.Text = numericUpDown.Value.ToString();}else{int value = Convert.ToInt32(UpDowns.Text);if (value > numericUpDown.Maximum){value = Convert.ToInt32(numericUpDown.Maximum);numericUpDown.Value = value;numericUpDown.Text = numericUpDown.Value.ToString();}else if (value < numericUpDown.Minimum){value = Convert.ToInt32(numericUpDown.Minimum);numericUpDown.Value = value;numericUpDown.Text = numericUpDown.Value.ToString();}}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.cpky.cn/p/11275.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot整合腾讯云邮件发送服务非STMP

SpringBoot整合腾讯云邮箱服务 1、pom配置 <!-- 腾讯云邮箱服务--><dependency><groupId>com.tencentcloudapi</groupId><artifactId>tencentcloud-sdk-java</artifactId><!-- go to https://search.maven.org/search?qtencen…

硬件15、PCB如何将元器件切换顶层和底层以及元器件布局对齐

器件切换顶层和底层 在移动元器件的时候&#xff0c;按一下 L 键&#xff0c;原器件就会变为蓝色&#xff0c;这就是放到了底层&#xff0c;然后再按 L 键就可以切换到顶层了 元器件放置后布局如何变得对齐那种 首先选中需要对齐的元器件&#xff0c;然后进行设置布局的属性…

vue3+threejs新手从零开发卡牌游戏(二十):添加卡牌被破坏进入墓地逻辑

在game目录下新建graveyard文件夹存放墓地相关代码&#xff1a; game/graveyard/p1.vue&#xff0c;这里主要设置了墓地group的位置&#xff1a; <template><div></div> </template><script setup lang"ts"> import { reactive, ref,…

Git常用指令使用

摘要&#xff1a;之前代码管理都是借助于fork、sourceTree等图形工具&#xff0c;最近发现直接用命令也好用&#xff0c;就总结Git常用的指令 1、Git的介绍 1.1 git官网 安装: Git - Downloading Packagehttps://git-scm.com/download/mac Mac上安装&#xff0c;直接使…

启扬RK3568核心板助力智慧步道轻装健身,打造全民健康生活新方式

随着物联网、AI智能等新技术的快速发展&#xff0c;智慧步道成为全国各地公园建设和全民健身公共服务设施改造的新主题。智慧步道基于物联网、人脸识别、大数据分析等技术&#xff0c;对人们的运动进行监测和数据采集&#xff0c;显示运动数据&#xff0c;包括里程统计、热量消…

钉钉服务端API报错 错误描述: robot 不存在;解决方案:请确认 robotCode 是否正确

problem 调用钉钉服务端API&#xff0c;机器人发送群聊消息&#xff0c;后台返回报错信息: 钉钉服务端API报错 错误描述: robot 不存在&#xff1b;解决方案:请确认 robotCode 是否正确&#xff1b; reason 定位: 登录后台&#xff0c;查看机器人是存在查看机器人调用权限接…