一个关于TComboBox控件的没有OnMouseDown事件的问题,怎么办??? 急。。。在线等待(200分)

  • 主题发起人 主题发起人 xiangding
  • 开始时间 开始时间
X

xiangding

Unregistered / Unconfirmed
GUEST, unregistred user!
如果我在StdCtrls单元中的TComBoBox加了一个属性,
property OnMouseDown;
但是如何让它出来在属性面板中?好像加了跟没加一样?
是不是要编译一下,怎么编译?

我现在要捕获TComboBox的鼠标右键,怎么做呀?它没有MouseDown事件。

当右键单击ComboBox时,我要显示另外一个窗体。。。
急,,,求大家帮帮忙,
我试了,加了OnMouseDown,但是只有在Combobox的最边上时单击鼠标才有用,如果在Combobx里的输入框里单击鼠标却没有用,它反而弹出window自带的那个copy,cut,paster...这个菜单....
UP一下也好。。。。
在线等。。。。。
还有,TComboBox如何加一个TreeView控件,我想下拉的是一个树,谁有源码吗??
 
鼠标右键问题:http://www.delphibbs.com/delphibbs/dispq.asp?lid=2194990
 
谢谢你,我试了,实现了一半的功能了,
右键是有用了,但是在之后还会弹出window那个菜单,该怎么去掉呢?
大侠帮帮忘记忙
 
如何再屏蔽掉原有的信息?
已经实现了右键,只是如何再屏蔽window弹出的那个: 剪切,复制,粘贴,的菜单


unit ComboBoxEC;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;

type
TComboBoxEC = class(TComboBox)
private
{ Private declarations }
FOnEditContextPopup: TContextPopupEvent;
protected
{ Protected declarations }
procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
ComboProc: Pointer); override;
procedure DoEditContextPopup(MousePos: TPoint; var Handled: Boolean); dynamic;
public
{ Public declarations }
published
{ Published declarations }
property OnEditContextPopup: TContextPopupEvent read FOnEditContextPopup write FOnEditContextPopup;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TComboBoxEC]);
end;

{ TComboBoxEC }

procedure TComboBoxEC.ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
ComboProc: Pointer);
var
hEdit: HWND;
Pt, Temp: TPoint;
Handled: Boolean;
msg: TWMContextMenu;
begin
Handled := False;

if (Style in [csDropDown, csSimple]) then hEdit := FindWindowEx(Handle, 0, 'Edit', nil)
else Exit;

if (ComboWnd = hEdit) and (Message.Msg = WM_CONTEXTMENU) then
begin
msg := TWMContextMenu(Message);
Pt := SmallPointToPoint(msg.Pos);
if InvalidPoint(Pt) then
Temp := Pt
else
begin
Temp := ScreenToClient(Pt);
if not PtInRect(ClientRect, Temp) then
begin
inherited;
Exit;
end;
end;

DoEditContextPopup(Temp, Handled);
end;

if not Handled then
inherited ComboWndProc(Message, ComboWnd, ComboProc);
end;

procedure TComboBoxEC.DoEditContextPopup(MousePos: TPoint;
var Handled: Boolean);
begin
if Assigned(FOnEditContextPopup) then FOnEditContextPopup(Self, MousePos, Handled);
end;

end.
 
procedure ComboBoxEc1.OnEditContextPopup(......);
begin
Handled:=True;//这样Windows那个菜单就不会显示出来了
//弹出你自己想要的菜单
//或者其它要做的事情
end;
 
还是不行,如果改为true,
那在设计时就不能选中了,
 
说错了,不是改控件,是在你的程序里面:
procedure TForm1.ComboBoxEC1EditContextPopup(Sender: TObject;
MousePos: TPoint; var Handled: Boolean);
begin
Handled := True;//这样Windows那个菜单就不会显示出来了
//弹出你自己想要的菜单
//或者其它要做的事情
end;

我试过,没问题的
 
不会吧,,,怎么我在设计时都拖不了呢?
出什么问题了?
而且在运行时也不没有反
 
to:独帅
我还是没有出来,在设计时就出问题了,动不了了.
 
还没有解决吗?
在我这里是没问题的。
要不把你的给我一份~~~
 
下面是我的代码:
unit ComboBoxEC;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls;

type
TComboBoxEC = class(TComboBox)
private
{ Private declarations }
FOnEditContextPopup: TContextPopupEvent;
protected
{ Protected declarations }
procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
ComboProc: Pointer); override;
procedure DoEditContextPopup(MousePos: TPoint; var Handled: Boolean); dynamic;
public
{ Public declarations }
published
{ Published declarations }
property OnEditContextPopup: TContextPopupEvent read FOnEditContextPopup write FOnEditContextPopup;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('xiangding', [TComboBoxEC]);
end;

{ TComboBoxEC }

procedure TComboBoxEC.ComboWndProc(var Message: TMessage; ComboWnd: HWnd;
ComboProc: Pointer);
var
hEdit: HWND;
Pt, Temp: TPoint;
Handled: Boolean;
msg: TWMContextMenu;
begin
Handled := True;
if (Style in [csDropDown, csSimple]) then hEdit := FindWindowEx(Handle, 0, 'Edit', nil)
else Exit;

if (ComboWnd = hEdit) and (Message.Msg = WM_CONTEXTMENU) then
begin
msg := TWMContextMenu(Message);
Pt := SmallPointToPoint(msg.Pos);
if InvalidPoint(Pt) then
Temp := Pt
else
begin
Temp := ScreenToClient(Pt);
if not PtInRect(ClientRect, Temp) then
begin
inherited;
Exit;
end;
end;

DoEditContextPopup(Temp, Handled);
end;

if not Handled then
inherited ComboWndProc(Message, ComboWnd, ComboProc);
end;

procedure TComboBoxEC.DoEditContextPopup(MousePos: TPoint;
var Handled: Boolean);
begin
if Assigned(FOnEditContextPopup) then FOnEditContextPopup(Self, MousePos, Handled);
end;

end.
 
to:独帅,
成功了,
原来是handled:= false; 要改为true,
忘了改,不好意思,
马上结贴
 
接受答案了.
 
后退
顶部