各位老师好:
我想实现如下功能:
当鼠标在listbox窗体上滑动时使滑过的文字高亮显示,我在listbox控件的Onmousemove(鼠标移动)事件中写了如下代码:
listbox1.itemindex:=y div 20;一个listbox窗体中有许多行文字,一个窗体内显示不完,如只能显示10行。如果鼠标在listbox窗体内的头10行滑动,则listbox中的文字高亮显示,可如果文字超过了第10行,则不能高亮显示,高亮显示的文字又变成了listbox窗体的前10行。我研究了很长时间这个问题,不能解决。望各位老师不吝指点。
我想实现如下功能:
当鼠标在listbox窗体上滑动时使滑过的文字高亮显示,我在listbox控件的Onmousemove(鼠标移动)事件中写了如下代码:
listbox1.itemindex:=y div 20;一个listbox窗体中有许多行文字,一个窗体内显示不完,如只能显示10行。如果鼠标在listbox窗体内的头10行滑动,则listbox中的文字高亮显示,可如果文字超过了第10行,则不能高亮显示,高亮显示的文字又变成了listbox窗体的前10行。我研究了很长时间这个问题,不能解决。望各位老师不吝指点。
解决方案 »
- 求解一个比较难的注入问题!
- 有谁安装过imageen3 我安装时提示File not found: 'jdapimin.obj',如何解决?
- MainMenu循环隐藏显示的问题
- 我用quickreport时候为什么我在编译的时候总是说“file not found :'QRPDFFilt.dcu' 啊?
- 不用webbrowser得到网页源代码
- IDFtp 问题,在线等待。。。。。。。
- 远程开机的方法?
- 如何让DBGRID这样显示?难问题!!!200分!!!
- 求教: delphi中 JPG图片怎样存入数据库中的BLOB字段?怎么进行VCD文件分割或存入BLOB字段?
- VC写得dll,参数为结构,delphi如何调用?
- 求教对Combobox中Items内容的判断方式?
- 怎样将文件存储到数据库中?
procedure TForm4.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
FRect: TRect;
begin
FRect := ListBox1.ItemRect(Index);
if odHotLight in State then
begin
ListBox1.Canvas.Brush.Color := clLime;
ListBox1.Canvas.FillRect(FRect);
ListBox1.Canvas.TextOut(FRect.Left, FRect.Top, ListBox1.Items[Index]);
end else if odSelected in State then
begin
ListBox1.Canvas.Brush.Color := clBlue;
ListBox1.Canvas.FillRect(FRect);
ListBox1.Canvas.DrawFocusRect(FRect);
ListBox1.Canvas.TextOut(FRect.Left, FRect.Top, ListBox1.Items[Index]);
end else
begin
ListBox1.Canvas.Brush.Color := clWhite;
ListBox1.Canvas.FillRect(FRect);
ListBox1.Canvas.TextOut(FRect.Left, FRect.Top, ListBox1.Items[Index]);
end;
end;procedure TForm4.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
FRect: TRect;
I, FItem: Integer;
State: TOwnerDrawState;
begin
FItem := ListBox1.ItemAtPos(Point(X, Y), True);
if FItem > -1 then
begin
FRect := ListBox1.ItemRect(FItem);
for I := 0 to ListBox1.Count - 1 do
begin
State := [odDefault];
if I = FItem then
include(State, odHotLight);
if ListBox1.ItemIndex = I then
include(State, odSelected);
ListBox1DrawItem(ListBox1, I, FRect, State)
end;
end;
end;