Focus on a PaintBox lazarus / 31-LCL ---------------------------------------------------------------------- Edson · 2014-09-25 15:51 I'm having problem on capturing keys for control an object drawn on a PaintBox. FAIK the PaintBox can 't ve focused, so can't capture the keyboard. How can I capture the keys for controlling a PaintBox?. I've tried putting the PaintBox in a ScrollBox, and setting his TabStop to True for to use the ScrollBox for Capture the keyboard, but it seems that the ScrollBox doesn't have the focus when it's covered by the PaintBox  . ---------------------------------------------------------------------- Rails · 2014-09-25 16:18 Try setting the paintbox's keypreview to true. The parent will intercept the child's keystrokes. Use these. Works that way with TCairoPaintBox. I assume TPaintBox would be the same ---------------------------------------------------------------------- Edson · 2014-09-25 17:00 Thanks for the response . PaintBox have not KeyPreview. Do you refer to the KeyPreview on the Form? I assume that I can intercept the Keys in this way, but meanwhile some Control must have the focus. Currently I have the PaintBox in a frame, and I don't want to make it dependent of the events of the Container (Form). ---------------------------------------------------------------------- engkin · 2014-09-25 17:21 IIRC, PaintBox does not have a window. All its messages come from its parent through calling its Perform to imitate a messaging system. So yes, no focus/keyboard messages for it. And yes, KeyPreview is for the form. ---------------------------------------------------------------------- howardpc · 2014-09-25 17:23 TPaintBox is a TGraphicControl descendant, so cannot accept focus or receive keystrokes. Any control you draw on its surface is merely a drawing, a mirage, and not the 'real thing'. Key events can only be processed by TWinControl descendants such as TEdit etc. which can be contained by your frame. TLabel is a graphic control exception that overrides the virtual DialogChar() method of TControl and watches for TLMKey messages so it can set the focus to an associated FocusControl when an accelerator key is pressed. Perhaps you could use a similar technique to extend TPaintBox, but you would be working against its design hierarchy which is to be oblivious of all key events. ---------------------------------------------------------------------- Edson · 2014-09-25 17:40 Maybe I must have chosen, another control for having Keyboard control. What will be the difference between using PaintBox or using a ScrollBox for drawing objects with TCanvas? ---------------------------------------------------------------------- engkin · 2014-09-25 17:58 Any control including/descendent of TCustomControl should work. All Custom Drawn controls are descendent of TCustomControl. ---------------------------------------------------------------------- Rails · 2014-09-25 19:10 Quote from: Rails on September 25, 2014, 06:18:58 pmTry setting the paintbox's keypreview to true. The parent will intercept the child's keystrokes. Use these. Works that way with TCairoPaintBox. I assume TPaintBox would be the same My apologies. I assumed (incorrectly) that TPaintBox would be the same in that regard as TCairoPaintBox. It isn't. I should have checked first.