SplitContainer Splitter Gets Focus Rectangle?
Hello,
I'm developing a Windows Forms application using tjhe VS .NET 2005 July CTP bits. What a tremendous piece of software! Miles ahead of previous versions.
One thing I'm noticing is that the new SplitContainer control gets a "Focus Rectangle" during moving that persists even after the resize is complete. I believe that this is a bug, since I've seen no other application ever with a focus rectangle on the splitter...
Can anyone comment? Is this normal UI behavior, and/or is it an open bug?
Thank you,
--Mike
[536 byte] By [
MikeP2] at [2007-12-16]
BTW I have taken a screenshot of my app showing to focus rectangle, but can't seem to figure out how to post images on this forum... If an image is needed, I can provide one.
--Mike
Another quick follow up.
Worse than the focus rectangle, the splitter is actually STEALING the focus! This means that if you're in an edit control, typing, and resize the splitter to make the edit control larger, and then resume typing--the edit control won't get your keystrokes because it no longer has the focus! I've confirmed that focus is taken away from both edit controls (one panel) and a listview (the other panel).
This focus behavior occurs even if I set "TabStop" on the SplitContainer to false.
--Mike
Hi Mike,The focus issue you mentioned is by design, however to get the performance you want, you can use the following workaround:
| | // Temp variable to store a previously focused control private Control focused = null; private void splitContainer1_MouseDown(object sender, MouseEventArgs e) { // Get the focused control before the splitter is focused focused = getFocused(this.Controls); } private Control getFocused(Control.ControlCollection controls) { foreach (Control c in controls) { if (c.Focused) { // Return the focused control return c; } else if (c.ContainsFocus) { // If the focus is contained inside a control's children // return the child return getFocused(c.Controls); } } // No control on the form has focus return null; } private void splitContainer1_MouseUp(object sender, MouseEventArgs e) { // If a previous control had focus if (focused != null) { // Return focus and clear the temp variable for // garbage collection focused.Focus(); focused = null; } } |
Let me know if you need any more help with this.Scott Morrison
WinForms PM
Microsoft Corp.
Scott:
Your solution worked perfectly. Thank you so much for taking the time to provide the code... It's modular enough to where it just dropped into the right locations in my project.
The behavior is now exactly as desired.
Thank you again. I'll update the "bug" with your solution on the msdn product feedback site. EDIT: The bug on the lab.msdn site has been updated to reflect this. I think this behavior and the workaround code provided should be included in updated documentation for the SplitContainer control.
--Mike