TComboBox [StdCtrls]
我的做法如下:在.h文件里加入三行鼠标消息的公布。
class PACKAGE TComboBox1 : public TComboBox
{
private:
protected:
public:
__fastcall TComboBox1(TComponent* Owner);
__published:
__property OnMouseMove;
__property OnMouseDown;
__property OnMouseUp;
};
//.cpp文件
#include <vcl.h>
#pragma hdrstop
#include "ComboBox1.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TComboBox1 *)
{
new TComboBox1(NULL);
}
//---------------------------------------------------------------------------
__fastcall TComboBox1::TComboBox1(TComponent* Owner)
: TComboBox(Owner)
{
}
//---------------------------------------------------------------------------
namespace Combobox1
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TComboBox1)};
RegisterComponents("Data Controls", classes, 0);
}
}
4 个解决方案
#1
TComboBox是一个组合型容器类控件,而通常的MouseDown或MouseUp以及MouseMove事件是目标唯一性事件(即通常情况下,其事件对应的主体唯一),在这类控件中通常封装MouseDown或MouseUp以及MouseMove事件一是实用性不大,二是不可能为每一个TComboBox的Control创建事件.如TComboBox默认的主Mouse事件的对象为一Button(下拉按纽),而你所需要的事件是Edit的事件.
比如最直接的Button(下拉按纽)的Mouse事件如下:
....
class PACKAGE TMComboBox : public TComboBox
{
private:
TMouseEvent FOnMouseDown;
TMouseEvent FOnMouseUp;
protected:
__declspec(dynamic) void __fastcall MouseDown(TMouseButton Button,Classes::TShiftState Shift,int X,int Y);
__declspec(dynamic) void __fastcall MouseUp(TMouseButton Button,Classes::TShiftState Shift,int X,int Y);
public:
__fastcall TMComboBox(TComponent* Owner);
__published:
__property TMouseEvent OnMouseDown = { read = FOnMouseDown, write = FOnMouseDown };
__property TMouseEvent OnMouseUp = { read = FOnMouseUp, write = FOnMouseUp };
};
void __fastcall TMComboBox::MouseDown(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseDown) FOnMouseDown(this,Button,Shift, X, Y);
}
//---------------------------------------------------------------------------
void __fastcall TMComboBox::MouseUp(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseDown) FOnMouseUp(this,Button,Shift, X, Y);
}
//---------------------------------------------------------------------------
比如最直接的Button(下拉按纽)的Mouse事件如下:
....
class PACKAGE TMComboBox : public TComboBox
{
private:
TMouseEvent FOnMouseDown;
TMouseEvent FOnMouseUp;
protected:
__declspec(dynamic) void __fastcall MouseDown(TMouseButton Button,Classes::TShiftState Shift,int X,int Y);
__declspec(dynamic) void __fastcall MouseUp(TMouseButton Button,Classes::TShiftState Shift,int X,int Y);
public:
__fastcall TMComboBox(TComponent* Owner);
__published:
__property TMouseEvent OnMouseDown = { read = FOnMouseDown, write = FOnMouseDown };
__property TMouseEvent OnMouseUp = { read = FOnMouseUp, write = FOnMouseUp };
};
void __fastcall TMComboBox::MouseDown(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseDown) FOnMouseDown(this,Button,Shift, X, Y);
}
//---------------------------------------------------------------------------
void __fastcall TMComboBox::MouseUp(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseDown) FOnMouseUp(this,Button,Shift, X, Y);
}
//---------------------------------------------------------------------------
#2
这三个鼠标事件去掉,还是要出错,
#3
路过看看
顺便up
顺便up
#4
rtl60.bpl是CB运行时所需要的动态链,检查一下是不是你的CB中没有或是这个文件出现错误了,更替下试一下,要是打包时,不包含这个文件是一定不行的,我们的文件在别人的机器上是运行不了的:)
#1
TComboBox是一个组合型容器类控件,而通常的MouseDown或MouseUp以及MouseMove事件是目标唯一性事件(即通常情况下,其事件对应的主体唯一),在这类控件中通常封装MouseDown或MouseUp以及MouseMove事件一是实用性不大,二是不可能为每一个TComboBox的Control创建事件.如TComboBox默认的主Mouse事件的对象为一Button(下拉按纽),而你所需要的事件是Edit的事件.
比如最直接的Button(下拉按纽)的Mouse事件如下:
....
class PACKAGE TMComboBox : public TComboBox
{
private:
TMouseEvent FOnMouseDown;
TMouseEvent FOnMouseUp;
protected:
__declspec(dynamic) void __fastcall MouseDown(TMouseButton Button,Classes::TShiftState Shift,int X,int Y);
__declspec(dynamic) void __fastcall MouseUp(TMouseButton Button,Classes::TShiftState Shift,int X,int Y);
public:
__fastcall TMComboBox(TComponent* Owner);
__published:
__property TMouseEvent OnMouseDown = { read = FOnMouseDown, write = FOnMouseDown };
__property TMouseEvent OnMouseUp = { read = FOnMouseUp, write = FOnMouseUp };
};
void __fastcall TMComboBox::MouseDown(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseDown) FOnMouseDown(this,Button,Shift, X, Y);
}
//---------------------------------------------------------------------------
void __fastcall TMComboBox::MouseUp(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseDown) FOnMouseUp(this,Button,Shift, X, Y);
}
//---------------------------------------------------------------------------
比如最直接的Button(下拉按纽)的Mouse事件如下:
....
class PACKAGE TMComboBox : public TComboBox
{
private:
TMouseEvent FOnMouseDown;
TMouseEvent FOnMouseUp;
protected:
__declspec(dynamic) void __fastcall MouseDown(TMouseButton Button,Classes::TShiftState Shift,int X,int Y);
__declspec(dynamic) void __fastcall MouseUp(TMouseButton Button,Classes::TShiftState Shift,int X,int Y);
public:
__fastcall TMComboBox(TComponent* Owner);
__published:
__property TMouseEvent OnMouseDown = { read = FOnMouseDown, write = FOnMouseDown };
__property TMouseEvent OnMouseUp = { read = FOnMouseUp, write = FOnMouseUp };
};
void __fastcall TMComboBox::MouseDown(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseDown) FOnMouseDown(this,Button,Shift, X, Y);
}
//---------------------------------------------------------------------------
void __fastcall TMComboBox::MouseUp(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
if (FOnMouseDown) FOnMouseUp(this,Button,Shift, X, Y);
}
//---------------------------------------------------------------------------
#2
这三个鼠标事件去掉,还是要出错,
#3
路过看看
顺便up
顺便up
#4
rtl60.bpl是CB运行时所需要的动态链,检查一下是不是你的CB中没有或是这个文件出现错误了,更替下试一下,要是打包时,不包含这个文件是一定不行的,我们的文件在别人的机器上是运行不了的:)