C++ MFC Problem
-
hi, I want to scroll window when someone press tab on text box. my problem is i have dynamically generated textboxes in a window and window size is fixed. so when there are more then 10 text boxes i am giving a scroll bar and allows user to scroll through the textboxes to enter the values. i want to allow users to press tab and go through all text box. so when user is at last visible text box and press enter, scroll bar should automatically scroll one textbox down. how can i archive this ?? please help.
-
hi, I want to scroll window when someone press tab on text box. my problem is i have dynamically generated textboxes in a window and window size is fixed. so when there are more then 10 text boxes i am giving a scroll bar and allows user to scroll through the textboxes to enter the values. i want to allow users to press tab and go through all text box. so when user is at last visible text box and press enter, scroll bar should automatically scroll one textbox down. how can i archive this ?? please help.
If you make your text boxes of a class you have derived from CEdit, then you can handle the WM_SETFOCUS message to know when a new edit box has gained focus after the user pressed tab. Since you now know which edit got the focus, you can use GetWindowRect() (followed by ScreenToClient() on the window that holds the edit boxes), and compare this to your window's client rect - *after* the current scroll position has been used to offset the top and bottom of the window's rect. This will tell you if the new edit control is visible; if it is not, you can determine which way to scroll to bring it visible. This can be achieved by calling SetScrollPos() on the scroll bar. I'm assuming you are comfortable with moving the edit controls to simulate being scrolled?
-
If you make your text boxes of a class you have derived from CEdit, then you can handle the WM_SETFOCUS message to know when a new edit box has gained focus after the user pressed tab. Since you now know which edit got the focus, you can use GetWindowRect() (followed by ScreenToClient() on the window that holds the edit boxes), and compare this to your window's client rect - *after* the current scroll position has been used to offset the top and bottom of the window's rect. This will tell you if the new edit control is visible; if it is not, you can determine which way to scroll to bring it visible. This can be achieved by calling SetScrollPos() on the scroll bar. I'm assuming you are comfortable with moving the edit controls to simulate being scrolled?
Thanks, Buddy