How do I specify a mouseDown eventhandler to dynaically creted Tpanels? My intention is to create a number of panels, like tiles, and move them around on the Form
I have created a design time TPanel and copied its OnMouseDown event and saved it as PanelMouseDown.
My code:

Pan:=TPanel.Create(Form2);
Pan.Height:=60;
Pan.Width:=60;
Pan.Parent:=Form2;
Pan.DragMode:=dmManual;
Pan.OnMouseDown :=Form2.PanelMouseDown;

I cant get the panels to react on mouseclicks. Does somebody have any suggestions?

Recommended Answers

All 4 Replies

That code looks okay. What's in the event handler? What happens when you step through it with the debugger?

Event handler never get trigged. Code for the moment is only beep;

Show the event handler.

Sorry bothering you all! I had put a label over the panel and the label covered the whole Panel so the Label was clicked instead of the Panel. Increasing the panel and clicking outside the label all worked well and the cration cod for the panel was correct. Thanks pritaeas for your engagement. Case closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.