Delphi CxCombobox 拦截滚轮事件,使之聚焦时文本框内的内容不随着滚轮的滚动而发生变化
2013-10-19 12:34
579 查看
在写程序时,我发现在滚动鼠标滚轮时,原意是想让整个页面向下Scroll,但是此时恰巧
页面焦点聚焦在Combobox的文本框内,滚动滚轮却是把Combobox内的内容给改变了。正常情况下这个也不影响什么,有时也方便操作,但是在此时的情况下无疑是不合适的,因为用户可能在不知情的情况下会把Combobox内的内容给改变,这无疑是不能发生的,
所以,我就自己写段代码,来阻止这种事情发生。
RzCombobox有滚轮事件,但是Delphi自带的Combobox还有Dev Express的cxCombobox没有此事件,那么我们就可以自己写代码来拦截滚轮事件,以下是代码:
页面焦点聚焦在Combobox的文本框内,滚动滚轮却是把Combobox内的内容给改变了。正常情况下这个也不影响什么,有时也方便操作,但是在此时的情况下无疑是不合适的,因为用户可能在不知情的情况下会把Combobox内的内容给改变,这无疑是不能发生的,
所以,我就自己写段代码,来阻止这种事情发生。
RzCombobox有滚轮事件,但是Delphi自带的Combobox还有Dev Express的cxCombobox没有此事件,那么我们就可以自己写代码来拦截滚轮事件,以下是代码:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Panel1: TPanel; ComboBox1: TComboBox; Label1: TLabel; procedure FormCreate(Sender: TObject); private { Private declarations } Procedure OnMouseWheel(Var Msg: TMsg; var Handled: Boolean); public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMessage := OnMouseWheel; end; procedure TForm1.OnMouseWheel(var Msg: TMsg; var Handled: Boolean); begin if Msg.message = WM_MOUSEWHEEL then begin //ShowMessage(ActiveControl.ClassName); if ActiveControl IS TComboBox then //Delphi自带Combobox //if ActiveControl.ClassName = 'TcxCustomComboBoxInnerEdit' then //CxCombobox begin Handled := True; end; end; end; procedure TForm1.FormDestroy(Sender: TObject); begin Application.OnMessage := nil; end; end.
相关文章推荐
- Delphi实现树型结构
- 让Delphi XE5跟其他版本的Delphi共存
- DelphiXE5如何获取Android手机SIM卡串号[转]
- Delphi的StringReplace 字符串替换函数
- delphi 选择目录对话框(SelectDirectory 函数)
- Delphi 选择文件夹对话框 (有新建文件夹按钮)修正版
- delphi中查找指定文件的例程
- delphi字符串操作函数一览
- Delphi Leftstr,Rightstr函数应用
- 在delphi中实现密码框“大写锁定打开”的提示
- Delphi 中PChar()函数的用法
- delphi Move操作
- DELPHI实现关闭指定进程,自身防杀
- (Delphi)New,Getmem,ReallocMem联系与区别(转)
- delphi xe2 string、AnsiString及Tbytes之间的转换
- Delphi XE5 Android 运行黑屏卡死的解决方法
- 【转】Delphi 文件拖放
- Delphi XE5 for Android (十一)
- Raknet 简单封装 For Delphi
- delphi的 ics的使用例子,ftp客户端上传的例子。