读书人

怎么在listbox右键能选定当前行并打开

发布时间: 2012-04-19 14:36:43 作者: rapoo

如何在listbox右键能选定当前行并打开菜单?
如何在listbox右键能选定当前行并打开菜单?

[解决办法]

Delphi(Pascal) code
procedure TForm1.ListBox1MouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var        i: integer;begin        i := ListBox1.ItemAtPos(Point(x,y),True);        if i>=0 then                ListBox1.ItemIndex := i;        if Button = mbRight then                PopupMenu1.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);end;
[解决办法]
Delphi(Pascal) code
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var    aPoint: TPoint;begin  if Button = mbRight then  begin    aPoint.x := x;    aPoint.y := y;    ListBox1.ItemIndex := ListBox1.ItemAtPos(aPoint,true);  end;end; 

读书人网 >.NET

热点推荐