Delphi Object and Component Reference
ItemRect exampleThis example uses a list box on a form. When the user clicks one of the items in the list box, a beep occurs if the mouse is in the first half of the item. A similar technique can be used to detect 揾ot?regions in an owner-draw list box:procedure TForm1.FormCreate(Sender: TObject);begin
with ListBox1 do
begin
Items.Add('Hello');
Items.Add('New');
Items.Add('World');
end;
end;procedure TForm1.ListBox1MouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var
ListBoxItem: TRect;
begin
if Button = mbLeft then
begin
ListBoxItem := ListBox1.ItemRect(ListBox1.ItemIndex);
if (Y > ListBoxItem.Top) and
(Y < ListBoxItem.Bottom) and
(X > ListBoxItem.Left) and
(X < (ListBoxItem.Left + ListBoxItem.Right) div 2) then
Beep;
end; end;
还有X,Y我知道是坐标,可是(X < (ListBoxItem.Left + ListBoxItem.Right) div 2)为什么要这样子写呢?(X > ListBoxItem.Right)不好吗?
ItemRect exampleThis example uses a list box on a form. When the user clicks one of the items in the list box, a beep occurs if the mouse is in the first half of the item. A similar technique can be used to detect 揾ot?regions in an owner-draw list box:procedure TForm1.FormCreate(Sender: TObject);begin
with ListBox1 do
begin
Items.Add('Hello');
Items.Add('New');
Items.Add('World');
end;
end;procedure TForm1.ListBox1MouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var
ListBoxItem: TRect;
begin
if Button = mbLeft then
begin
ListBoxItem := ListBox1.ItemRect(ListBox1.ItemIndex);
if (Y > ListBoxItem.Top) and
(Y < ListBoxItem.Bottom) and
(X > ListBoxItem.Left) and
(X < (ListBoxItem.Left + ListBoxItem.Right) div 2) then
Beep;
end; end;
还有X,Y我知道是坐标,可是(X < (ListBoxItem.Left + ListBoxItem.Right) div 2)为什么要这样子写呢?(X > ListBoxItem.Right)不好吗?
解决方案 »
- 申请担任CSDN数据库板块的版主
- oracle中blob字段操作,insert可以,update不行,怎么回事
- 客户端无法访问sqlserver服务器(急啊)
- 如何在点按钮前检查编辑框是否空,如空则取消点击事件,焦点指向为空的编辑框
- 查询结果输出到EXCEL
- 在学习WIN2000中开发服务型的多层应用程序,执行中出现以下错误……
- 取出时间日期字段中的时间问题
- 心里很急,怎样利用程序与网页的填写项交互?
- 各位高手帮帮忙!
- 紧急在线等候,怎样得到网卡的id号?
- 怎么读取系统的日志?OpenEventLog,ReadEventLog的详细用法
- 本人想从麦克风中采集音频数据,读到内存中,并从网络中发出;不知道用DSPACK组件如何实现?
还有X,Y我知道是坐标,可是(X < (ListBoxItem.Left + ListBoxItem.Right) div 2)为什么要这样子写呢?(X > ListBoxItem.Right)不好吗?
例中要求在条目的前半部时发声
(ListBoxItem.Left + ListBoxItem.Right) div 2为listbox的中间x坐标