|
-
October 7th, 2011, 08:44 AM
#4
Re: focus on form...
 Originally Posted by smallbit
Thats is a tricky solution but won't work, because the panel mousewhell event never fires. [...]
Oh... I interpreted this sentence from your OP:
 Originally Posted by smallbit
I guess that focus is on gl panel because its mouse events are executed correctly.
like the MouseWheel event of the panel would work, just like the panel's other mouse evets.
 Originally Posted by smallbit
[...] Other events i need to use (mose move etc) works correctly. I can't disable it for that reason.
Perhaps we have a misunderstanding here: I didn't mean to disable the panel, but the native window it hosts, i.e. the COpenGL instance, by creating it with the additional window style WS_DISABLED.
[...]
The GlPanel is a System::Windows::Forms::Panel so the mousewheel event should obviously work.
Agreed.
One solution I have found is to force the focus to one of the form elements in example a button in glpanel Mouse move event. With that it works correctly.
This is not very elegant but works.
Actually, I was considering an approach like that too when writing my last post, but refrained from posting it because it would very likely irritate the user by every now and then having the focus jump to that button for no apparent reason. In the meantime, however, I had an idea how to improve the approach: Give every control that's candidate to resetting the focus to it an event handler like this:
Code:
void Form1::button1_GotFocus(Object ^sender, EventArgs ^e)
{
m_ctlLastFocused = safe_cast<Control ^>(sender);
}
where m_ctlLastFocused is a form class member variable of type Control ^. Of course you can also use the control variable (button1 in the above case) instead of the cast sender parameter, but then each control would need its own event handler. The way I've written it above, you can use the same singular handler for all the controls in question. Should any of the controls already have a specific handler for that event, you can forward the event from there to the generic handler by simply calling it, much like forwarding the MouseWheel event as I described above.
Then, when you want to reset the focus, you use a line quite similar to the one you seem to be using at the moment:
Code:
m_ctlLastFocused->Focus();
Alternatively, you may use the Enter event for that purpose instead of GotFocus, which according to MSDN is the preferable option. See http://msdn.microsoft.com/en-us/libr....gotfocus.aspx.
I have tried to give focus to the form itself but since I "am" in the glpanel this->Focus(); won't work. And any other attempt fails too. I must admin I have no idea how to adress the Form there in order to make it work  .
If you "are" in the panel, I suggest to try Parent->Focus(); instead. Surprisingly simple, isn't it? However, I'm afraid the Focus() method may not have the desired effect when called on a form (didn't test that, though). But as it's really little effort, I think it's worth a try anyway.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|