急!keypress 问题

本文探讨了在Delphi中使用键盘事件处理函数时遇到的问题,即如何限制输入为字母、数字或汉字。通过修改KeyPress事件处理函数,确保用户只能输入这三类字符。
急!keypress 问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061222105416169.html
if   (Key   <#48)or   ((Key   >#57)and   (Key   <#65))or   ((Key   >#90)and   (Key   <#97))   or   (Key   >#122)   then  
                Key   :=#0  
   
  不能输入汉字,该怎麽改?我要求只能输入字母,数字,汉字。  
  本人不清楚   key   值,请赐教。

procedure   TForm1.Edit1KeyPress(Sender:   TObject;   var   Key:   Char);  
  begin  
      if   not   ((Key   <   #32)   or   (Key   in   ['0'..'9',   'a'..'z',   'A'..'Z'])   or   (Key   >   #127))   then  
          Key   :=   #0;  
  end;  
 

转载于:https://www.cnblogs.com/delphi2007/archive/2008/12/11/1352495.html

<!doctype html> <html class="no-js" lang=""> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> <link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="css/kuding.css"> <link rel="stylesheet" href="css/product-styles.css"> <meta name="description" content=""> <meta property="og:title" content=""> <meta property="og:type" content=""> <meta property="og:url" content=""> <meta property="og:image" content=""> <meta property="og:image:alt" content=""> <link rel="icon" href="/favicon.ico" sizes="any"> <link rel="icon" href="/icon.svg" type="image/svg+xml"> <link rel="apple-touch-icon" href="icon.png"> <link rel="manifest" href="site.webmanifest"> <meta name="theme-color" content="#fafafa"> </head> <body> <script > // 搜索框点击显示下拉面板 const searchInput = document.getElementById('search-input'); const searchDropdown = document.getElementById('search-dropdown'); const searchContainer = document.querySelector('.search-container'); const resultPage = document.getElementById('result-page'); searchInput.addEventListener('focus', () => { searchDropdown.style.display = 'block'; }); // 点击页面其他区域隐藏下拉面板 document.addEventListener('click', (e) => { if (!searchContainer.contains(e.target)) { searchDropdown.style.display = 'none'; } }); // 跳转到搜索结果页面 function goToResult(keyword) { const resultTitle = document.getElementById('result-title'); resultTitle.textContent = `搜索结果:${keyword}`; searchContainer.style.display = 'none'; resultPage.style.display = 'block'; } // 返回搜索页面 function goBack() { resultPage.style.display = 'none'; searchContainer.style.display = 'block'; } // 搜索按钮逻辑 const searchBtn = document.getElementById('search-btn'); searchBtn.addEventListener('click', () => { const keyword = searchInput.value.trim(); if (keyword) { goToResult(keyword); // 实际项目中可在此处添加“添加到历史搜索”逻辑 } }); </script> <div class="AllDiv"> <!---顶部菜单栏(固定位置和高度:100px)---> <div class="TopNavigation"> <div id="toplogo">XianCai</div> <div class="search-container"> <!-- 搜索框区域 --> <div class="search-box"> <input type="text" id="search-input" placeholder="搜索你想要的宝贝..."> <button id="search-btn">搜索</button> </div> <!-- 搜索下拉面板(默认隐藏,点击搜索框显示) --> <div class="search-dropdown" id="search-dropdown"> <!-- 历史搜索 --> <div class="dropdown-section"> <h3 class="section-title">历史搜索</h3> <ul class="history-list" id="history-list"> <li class="history-item" onclick="goToResult('二手笔记本电脑')">二手笔记本电脑</li> <li class="history-item" onclick="goToResult('闲置连衣裙')">闲置连衣裙</li> <li class="history-item" onclick="goToResult('家用咖啡机')">家用咖啡机</li> <li class="history-item" onclick="goToResult('考研真题')">考研真题</li> </ul> </div> <!-- 推荐搜索 --> <div class="dropdown-section"> <h3 class="section-title">大家都在搜</h3> <ul class="recommend-list" id="recommend-list"> <li class="recommend-item" onclick="goToResult('二手手机')">二手手机</li> <li class="recommend-item" onclick="goToResult('露营装备')">露营装备</li> <li class="recommend-item" onclick="goToResult('儿童绘本')">儿童绘本</li> <li class="recommend-item" onclick="goToResult('厨房小家电')">厨房小家电</li> </ul> </div> </div> </div> <!-- 搜索结果页面(默认隐藏) --> <div class="result-page" id="result-page" style="display: none;"> <div class="back-btn" onclick="goBack()">← 返回搜索</div> <h2 class="result-title" id="result-title">搜索结果:</h2> <p class="result-tip">点击历史/推荐项后,此处会显示对应关键词的搜索结果(实际项目中需对接后端接口)</p > </div> </body> </html>
09-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值