请问:如何知道combobox的光标到某个item的事件.(200分)

  • 主题发起人 主题发起人 apus
  • 开始时间 开始时间
A

apus

Unregistered / Unconfirmed
GUEST, unregistred user!
注意:
还没有select,只是光标移动到!
头次提问,请多关照,分提高不了,最多了。
 
>>combobox的光标到某个item的事件.
没有这个事件。
 
这个没有的,除非你自己修改原代码或者找其他的控件
 
>> 还没有select,只是光标移动到!

你想在这个事件中作什么?也许其它的事件可以代替这个事件。
 
沒有這個事件
可以用其它來代替呵
 
没有相应的windows消息吗?
有啥替代品?
 
这个我不知道。
 
没有 Select 好像没有
 
那位大侠做过类似的工作,我知道没有,但有没有里斯的vcl控件.
谁可提供线索.[blue][/blue]
 
好像没有,除非你换个控件。
 
SendMessage(ComboBox1.Handle, CB_GETCURSEL, 0, 0)的返回值就是。
 
如果想写个控件,谁有提示?
 
TCombobox没有这个事件,你可以改从它继承写一个新的控件:
截获 CB_SETCURSEL 消息就可以。
 
{*******************************************************************************
发表新控件:TComBoBoxCS;
功能:添加事件:OnSelChange(),触发时间是TComBoBoxCS的光标在item之间移动的时候.
添加属性:CurSelItem,可以获得光标位于哪个item上
-1为没有,0为第一条item,1为第二条item,依此类推...
欢迎使用、修改、完善,欢迎交流(9on9@sina.com)
********************************************************************************}
unit ComBoBoxCS;

interface

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

type
TComBoBoxCS = class(TComboBox)
private
{ Private declarations }
FOnSelChange: TNotifyEvent;
FCurSelItem: Integer;
protected
{ Protected declarations }
procedure WndProc(var Message: TMessage); override;
procedure SelChange;
public
{ Public declarations }
published
{ Published declarations }
property OnSelChange: TNotifyEvent read FOnSelChange write FOnSelChange;
property CurSelItem: Integer read FCurSelItem;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Mr.Nono', [TComBoBoxCS]);
end;

{ TComBoBoxCS }

procedure TComBoBoxCS.SelChange;
begin
if Assigned(FOnSelChange) then
FOnSelChange(Self);
end;

procedure TComBoBoxCS.WndProc(var Message: TMessage);
begin
inherited WndProc(Message);
case Message.Msg of
WM_CTLCOLORLISTBOX:
begin
FCurSelItem := SendMessage(Handle, CB_GETCURSEL, 0, 0);
SelChange;
end;
end;
end;

end.
 
独帅Sir:
你是否测试了代码? 似乎有问题?

另:你是否太喜欢CS?
 
独帅Sir:
或者我的测试方法不对,你可否告知怎么测试。
 
//当光标在items中移动时,就会触发OnSelChange事件,这时候你可以通过访问其CurSelItemunit属性
//来获取当前光标的位置(索引)
//CS:Cursor Select,随便起的名字,本想叫ComBoBoxEX,可是已经有了[:D]。
//与那个游戏CS没有任何关系,说实话,我不喜欢CS,也从来没有玩过。
//看看下面的程序是不是你要的:
Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComBoBoxCS;

type
TForm1 = class(TForm)
ComBoBoxCS1: TComBoBoxCS;
procedure ComBoBoxCS1SelChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ComBoBoxCS1SelChange(Sender: TObject);
begin
Caption := IntToStr(ComBoBoxCS1.CurSelItem);
end;

end.
 
独帅Sir:
你的这句话: //当光标在items中移动时,就会触发OnSelChange事件,
似乎和我想的有点出入。
当选中item时会触发OnSelChange事件,但是当光标在items间移动时似乎并不触发。
请测试。
谢谢,希望你继续。

 

Style设置为csOwnerDrawFixed或者csOwnerDrawVariable,
OnDrawItem事件中的Index就是你要的值。
 
to: apus
//但是当光标在items间移动时似乎并不触发
我上面的程序在运行时,当光标在items间移动时,窗口的标题栏应该是当前光标所在的item的索引值,
请问你是如何测试的呢?还是我没看懂你的问题?
请你做一个最简单的测试程序发到我的信箱好吗?最好把可执行程序给我发过来,放假后就只能在网吧
上网了。
 
后退
顶部