⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 20001005002.htm

📁 C++Builder教学大全
💻 HTM
字号:
<HTML>

<HEAD>

 

<TITLE>用Enter键控制焦点切换的方法</TITLE>



<META content="MSHTML 5.00.2314.1000" name=GENERATOR>

</HEAD>

<BODY aLink=#FF0000 bgColor=#ffffff leftMargin=0 link=#187800 topMargin=0 

vLink=#990099>



<div align="center">

  <table width="744" border="0" cellspacing="0" cellpadding="0" height="76">

    <tr> 

      <td> 

        <p align=center><font size="3"><br>

          <b>用Enter 键 控 制 焦 点 切 换 的 方 法<font color=#0000ff><big><big> </big></big></font></b></font></p>

        <p><font color=#333333>在Windows环境下,要使一个控件取得焦点,可在该控件上用鼠标单击一下,或按Tab键将焦点移至该控件上。这种控制焦点切换的方法有时不符合用户的习惯。用户希望用Enter键,控制焦点由Edit1切换到Edit2。要实现这样的功能需借助WinAPI函数SendMessage来完成。方法是:先设Form1的KeyPreview属性为true,然后在Form1的OnKeyPress事件中加入如下的代码。这样,用户就可以通过按Enter,键控制焦点按定义好的Taborder顺序来移动了 !</font> <br>

          <font 

color=#333333>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

          void __fastcall TForm1::FormKeyPress(TObject *Sender, char &amp;Key)</font> 

          <br>

          <font 

color=#333333>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

          {</font> <br>

          <font 

color=#333333>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

          if(Key==VK_RETURN)</font><font color=#333333></font> 

        <p><font 

color=#333333>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

          {</font> <br>

          <font 

color=#333333>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

          SendMessage(this- &gt;Handle,WM_NEXTDLGCTL,0,0);</font> <br>

          <font 

color=#333333>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

          Key=0;</font> <br>

          <font 

color=#333333>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

          }</font> <br>

          <font 

color=#333333>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

          }</font> </p>

    </td>

    </tr>

  </table>

 

</div>

</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -