delphi – 如何在TcxComboBox中抑制鼠标滚轮
发布时间:2020-12-15 09:30:18 所属栏目:大数据 来源:网络整理
导读:对于表单上的所有组合组件,我需要使用鼠标滚轮禁用滚动项目. 最重要的是拥有或多或少的通用解决方案,因为表单的设计可能会发生变化,如果在没有任何额外的源代码工作的情况下忽略新的组合组件会更好. 我有两种类型的组合:TComboBox和TcxComboBox(来自DevExpr
对于表单上的所有组合组件,我需要使用鼠标滚轮禁用滚动项目.
最重要的是拥有或多或少的通用解决方案,因为表单的设计可能会发生变化,如果在没有任何额外的源代码工作的情况下忽略新的组合组件会更好. 我有两种类型的组合:TComboBox和TcxComboBox(来自DevExpress ExpressBars Suit). 我试着这样走: procedure TSomeForm.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); begin if (Screen.ActiveControl is TComboBox) or (Screen.ActiveControl is TcxComboBox) then Handled := True; end; 它适用于TComboBox,但是当TcxComboBox具有焦点时,此事件处理程序从未触发. procedure TSomeForm.WndProc(var m: TMessage); begin if (m.Msg = WM_VSCROLL) or (m.Msg = WM_HSCROLL) or (m.msg = WM_Mousewheel) then m.Msg := 0; inherited; end; 但这样的消息永远不会来到这个处理程序 procedure TSomeForm.FormCreate(Sender: TObject); begin cxComboBox1.Properties.UseMouseWheel := False; end; 但它不起作用,仍然可以使用鼠标滚轮滚动项目.我发布了这个问题的支持票,但即使他们在下一个版本中修复它我现在需要一些解决方案. 任何想法,也许有人以某种方式解决了它? 解决方法
您可以继承自己的组件或使用重写DoMouseWheel的插入器类,而不是挂钩表单.您可以绑定其他属性上的处理.
type TcxComboBox = Class(cxDropDownEdit.TcxComboBox) function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override; private FUseMouseWheel: Boolean; public Property UseMouseWheel: Boolean Read FUseMouseWheel Write FUseMouseWheel; End; TComboBox = Class(Vcl.StdCtrls.TComboBox) function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; override; private FUseMouseWheel: Boolean; public Property UseMouseWheel: Boolean Read FUseMouseWheel Write FUseMouseWheel; End; TForm3 = class(TForm) ComboBox1: TComboBox; cxComboBox1: TcxComboBox; cxComboBox2: TcxComboBox; procedure FormCreate(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form3: TForm3; implementation {$R *.dfm} { TComboBox } function TComboBox.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; begin if FUseMouseWheel then inherited else Result := true; end; { TcxComboBox } function TcxComboBox.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint): Boolean; begin if FUseMouseWheel then inherited else Result := true; end; procedure TForm3.FormCreate(Sender: TObject); begin cxComboBox2.UseMouseWheel := true; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |