转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
dephi 程序输入法中英文自动切换实现的源代码         ★★★★

dephi 程序输入法中英文自动切换实现的源代码

作者:闵涛 文章来源:闵涛的学习笔记 点击数:749 更新时间:2009/4/23 18:44:17

现在将源代码公布出来,来谢谢大家的支持。本人水平有限,大家有什么号的灵感或建议,请 email  wang517@21cn.com.多谢!!

原代码实现的思路:

   提供一个列举系统所有输入法的窗体,供用户选择,将选择的中文输入法保存到系统注册表里。

 提供一个方法 ChangeYouFormAllControlIme(form)  ,form 是需要输入的窗体名称,枚举出相应窗体具有输入法的控件。

提供一个方法 JugeClassType(PClass:Tcontrol),判断每一个控件的实际类型,根据其ImeMode(为了程序设计简便,当值 为imchinese 时,切换为用户选择的中文输入法 ,其它切换为英文)

下面是主要原代码:

//判断控件类型切换中英文这个只能具体判断,无法用 Twincontrol 笼统判别或概括

procedure JugeClassType(PClass:Tcontrol;
begin
if pclass is TEdit then
 begin
   if TEdit(pclass).ImeMode=imchinese then
     TEdit(pclass).ImeName:=StrImeName (StrImeName  注册表保存的中文输入法名)同)
   else
     TEdit(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is TMemo then
 begin
   if TMemo(pclass).ImeMode=imchinese then
     TMemo(pclass).ImeName:=StrImeName
   else
     TMemo(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is TComboBox then
 begin
   if TComboBox(pclass).ImeMode=imchinese then
     TComboBox(pclass).ImeName:=StrImeName
   else
     TComboBox(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is TRichEdit then
 begin
   if TRichEdit(pclass).ImeMode=imchinese then
     TRichEdit(pclass).ImeName:=StrImeName
   else
     TRichEdit(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is TDBGrid then
 begin
   if TDBGrid(pclass).ImeMode=imchinese then
     TDBGrid(pclass).ImeName:=StrImeName
   else
     TDBGrid(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is TDBEdit then
 begin
   if TDBEdit(pclass).ImeMode=imchinese then
     TDBEdit(pclass).ImeName:=StrImeName
   else
     TDBEdit(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is TDbMemo then
 begin
   if TDbMemo(pclass).ImeMode=imchinese then
     TDbMemo(pclass).ImeName:=StrImeName
   else
     TDbMemo(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is TDbcombobox then
 begin
   if TDbcombobox(pclass).ImeMode=imchinese then
     TDbcombobox(pclass).ImeName:=StrImeName
   else
     TDbcombobox(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is Tdblookupcombobox then
 begin
   if Tdblookupcombobox(pclass).ImeMode=imchinese then
     Tdblookupcombobox(pclass).ImeName:=StrImeName
   else
     Tdblookupcombobox(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is Tdbrichedit then
 begin
   if Tdbrichedit(pclass).ImeMode=imchinese then
     Tdbrichedit(pclass).ImeName:=StrImeName
   else
     Tdbrichedit(pclass).ImeMode:=imClose;
   exit;
 end;
if pclass is TMaskEdit then
 begin
   if TMaskEdit(pclass).ImeMode=imchinese then
     TMaskEdit(pclass).ImeName:=StrImeName
   else
     TMaskEdit(pclass).ImeMode:=imClose;
   exit;
 end;
end;

//这个方法,您只需要在需要切换中英文的窗体 oncreate 事件里调用就可以了。YFormName,需要切换中英文的窗体。

Procedure ChangeYouFormAllControlIme(YFormName:TWinControl);
var
i:integer;
ChildControl:TControl;
Reg:TRegistry;
YouFormOrOTher:Twincontrol;
begin
YouFormOrOTher:=YFormName;
reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
try
 if Reg.OpenKey(''''\Software\IMeCustom'''',false)=true then
   StrImeName:=reg.ReadString(''''CustomIMeName'''');
finally
 reg.CloseKey;
 reg.Free;
end;
for i:=0 to YouFormOrOTher.ControlCount-1 do
 begin
   ChildControl:=YouFormOrOTher.Controls[i];
   JugeClassType(ChildControl);
   if ChildControl is TWinControl then ChangeYouFormAllControlIme(ChildControl as TWinControl);
 end;
end;
end.

枚举输入法,并将用户的选择保存到注册表里,很简单,这个大家可以自己实现。例如

ListBox1.Items:=screen.Imes;

 


[Delphi程序]dephi 程序输入法根据用户的爱好自动切换的简便解…  
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台