CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C++ Builder >  基础类

如何判断form中的某个控件是否拥有输入焦点?

楼主Netguy(老家伙)2001-08-20 11:13:18 在 C++ Builder / 基础类 提问

比如一个form中有两个grid,如何得知用户当前选中的是哪个grid? 问题点数:60、回复次数:14Top

1 楼lynu(南拳王)回复于 2001-08-20 11:21:57 得分 10

TForm有一个ActiveControl属性指明当前得到焦点的控件.  
  Top

2 楼wxcwuxuchun(清风)回复于 2001-08-20 11:23:30 得分 10

Focused(),请你看看帮助Top

3 楼Netguy(老家伙)回复于 2001-08-20 11:24:36 得分 0

谢谢。我试试。  
   
  具体说,是想达到如下的效果:  
  当用户点击form中的“添加”按钮时,如果第一个grid拥有焦点,则给第一个grid添加一行;如果第2个grid拥有焦点,则给第2个grid添加一行。Top

4 楼wow228(合欢猪)回复于 2001-08-20 11:31:01 得分 5

凡是基于TwinControl的控件都可以接受输入焦点!  
  Top

5 楼Netguy(老家伙)回复于 2001-08-20 11:34:11 得分 0

单步跟了一下,由于grid中的每个cell也是个可以接受输入焦点的控件,用form->ActiveControl得到的值似乎不是某个grid的指针。Top

6 楼wxcwuxuchun(清风)回复于 2001-08-20 11:35:01 得分 5

if   (grid1.focused())    
      //insert   1  
  else   if   (grid2.focused())  
      //insert   2  
  Top

7 楼Netguy(老家伙)回复于 2001-08-20 11:39:56 得分 0

选中一个grid并将光标集中在其中一个cell上,当点击了“确定”按钮后,两个grid的Focused(   )方法都返回fasle   ;(Top

8 楼wujinbao(abao)回复于 2001-08-20 11:41:11 得分 10

if(ActiveControl   ==Grid1)  
      //insert   1;  
  else   if(ActiveControl   ==   Grid2)  
      //insert   2;Top

9 楼gloom(苍狗白云)回复于 2001-08-20 11:46:01 得分 10

用API吧,GetFocus()Top

10 楼gloom(苍狗白云)回复于 2001-08-20 11:46:55 得分 0

GetFocus              
   
  The   GetFocus   function   retrieves   the   handle   of   the   window   that   has   the   keyboard   focus,   if   the   window   is   associated   with   the   calling   thread's   message   queue.    
   
  HWND   GetFocus(VOID)  
   
   
  Parameters  
   
  This   function   has   no   parameters.    
   
  Return   Values  
   
  If   the   function   succeeds,   the   return   value   is   the   handle   of   the   window   with   the   keyboard   focus.   If   the   calling   thread's   message   queue   does   not   have   an   associated   window   with   the   keyboard   focus,   the   return   value   is   NULL.    
   
  Remarks  
   
  Even   if   GetFocus   returns   NULL,   another   thread's   queue   may   be   associated   with   a   window   that   has   the   keyboard   focus.    
  Use   the   GetForegroundWindow   function   to   retrieve   the   handle   to   the   window   with   which   the   user   is   currently   working.   You   can   associate   your   thread's   message   queue   with   the   windows   owned   by   another   thread   by   using   the   AttachThreadInput   function.    
   
  See   Also  
   
  AttachThreadInput,   GetForegroundWindow,   SetFocus,   WM_KILLFOCUS,   WM_SETFOCUS    
   
  Top

11 楼Netguy(老家伙)回复于 2001-08-20 12:21:12 得分 0

用Spy++看了一下,发现都是因为点了“确定”按钮的缘故,点了之后焦点就跑到这个按钮上去了,两个grid都失去了焦点。奈何?Top

12 楼Netguy(老家伙)回复于 2001-08-20 12:55:06 得分 0

加分。  
   
  如何在点击“添加”按钮之前保存焦点的位置(即在切换焦点之前记下焦点在哪个控件上)?难道要重载OnMouseDown(   )并用GetFocus(   )获得当前焦点?有无其它办法?Top

13 楼xzgyb(老达摩)回复于 2001-08-20 12:59:48 得分 10

在两个dbgird的OnExit事件中保留一变量值来跟踪是哪一dbgird,  
  然后在确定按纽里在判断,行吗  
  Top

14 楼Netguy(老家伙)回复于 2001-08-20 13:10:33 得分 0

好的,就按xzgyb(回首往事,不堪回首)说的办。  
  结帖子。谢谢大家Top

相关问题

  • 怎么判断IP address控件中输入IP的合法性?
  • 怎么判断TEdit控件所输入的字符是数字还是字母?
  • 如何判断Text控件里输入的是非数字型数据?
  • 在Edit控件中输入字符, 如何判断光标的当前位置。
  • 怎样判断edit控件中输入的是数字,而不是文本?
  • 如何判断EDIT控件中的输入的为数值,而非字符
  • CEdit控件如何判断输入内容是英文还是汉字
  • 请问如何判断edit控件里面输入的是不是汉字啊?急
  • 如何读取(或判断)Text or Richtextbox控件中刚输入的字符(或汉字)
  • 怎么判断我的myform里是不是有名称叫TXT的输入框控件?

关键词

  • 控件
  • grid
  • 焦点
  • getfocus
  • 输入
  • activecontrol
  • 添加
  • keyboard focus
  • 按钮
  • focused

得分解答快速导航

  • 帖主:Netguy
  • lynu
  • wxcwuxuchun
  • wow228
  • wxcwuxuchun
  • wujinbao
  • gloom
  • xzgyb

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo