How to create tlistbox at runtime at mouse cursor location lazarus / 31-LCL ---------------------------------------------------------------------- AlistairG · 2011-03-09 13:36 Hi can anyone tell me whats wrong with my code below, as listbox is not at cursor location; it should appear whenever needed at mouse cursor position which might be anywhere on desktop (I havent got the hotkeys working yet). Also, should the owner be self or lb? Thank you: Code: [Select]Private lb:Tlistbox; //global var Mousepos:TPoint; procedure Tmainform.TrayIcon1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button=mbright then popupmenu1.PopUp() else begin GetCursorPos(Mousepos); if lb=nil then lb:=tlistbox.Create(lb); lb.Items.Add('lbnew'); //test case put anything on lb.left:=Mousepos.X; lb.Top:=Mousepos.Y; lb.visible:=true; lb.Show; lb.Invalidate; end; end; ---------------------------------------------------------------------- typo · 2011-03-09 14:33 Where do you want to show this listbox? You need a form to do this. Again, you are using a mousedown event handler to do what PopupMenu property would do better. ---------------------------------------------------------------------- AlistairG · 2011-03-09 18:39 Quote from: typo on March 09, 2011, 03:33:30 pmWhere do you want to show this listbox? You need a form to do this. Again, you are using a mousedown event handler to do what PopupMenu property would do better. Thanks for the info I'll work on it with a new form. I have been following your info about the popupmenu, but reason that location was used is its a location it will appear. In fact, at that location, it might make more sense to dynamically create additional popup menu items, which are the clipboard items that this program is handling it should appear whenever needed at mouse cursor position which might be anywhere on desktop (I havent got the hotkeys working yet).