Profile Picture

How do I focus a Canvas programmatically?

Posted By Karl Hulme 9 Years Ago
Author
Message
Karl Hulme
Question Posted 9 Years Ago
View Quick Profile
Forum Guru

Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 6, Visits: 16
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?

Karl Hulme
This post has been flagged as an answer
Posted 9 Years Ago
View Quick Profile
Forum Guru

Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)Forum Guru (50 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 6, Visits: 16
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!



Similar Topics


Reading This Topic