How do I focus a Canvas programmatically?


https://www.nevron.com/Forum/Topic9340.aspx
Print Topic | Close Window

By Karl Hulme - 9 Years Ago
Whenever I call NCanvas.Focus() it always returns false.

I've set NCanvas.AllowFocus to true, along with .AllowMouseCapture and .AllowDrop and .AllowTabStop.
I've also provided a FocusDecorator by specifying a color and stroke width. (This works occasionally but I'm not sure what's triggering when this does or doesn't appear)

I'm using the NCanvas.GotFocus and LostFocus events to determine if focus has been achieved.  My real interest is using the KeyDown event.

I find that I can tab into the canvas from the NTab parent, and then all the events fire as required.
But I cannot focus the canvas simply by clicking on it, or by calling NCanvas.Focus().

What am I missing?
By Karl Hulme - 9 Years Ago
My problem is related to calling SetFocus from the constructor.
Calling SetFocus from the MouseDown event of the canvas works fine, and the FocusDecorator seems perfectly consistent now too.

I spent hours trying to figure this one out.  And then solved it within minutes of posting on this forum - d'oh!