Link to home
Start Free TrialLog in
Avatar of nsgonline
nsgonline

asked on

Using Tab key with Picture box containing Forms

Hi, I have created a Picture box on a Main form (frmGroups). I open other forms inside of this Picture box on frmGroups. It works perfect except for using Tab key to move field-to-field within a form. Tab key seem to be working only on the Main form (frmGroups), but it doesn't sets focus on the fields on forms inside Picture box. I want to be able to use Tab key just like the way it works on a single form. I mean, tab key should set focus on the fields on form in Picture box as well as it should focus on frmGroups once the user ran through all the fields of a form inside picture box.

Any help this regard will be greatly appreciated. Thanks to all those experts.
Avatar of supunr
supunr

"Picture box on a Main form (frmGroups). I open other forms inside of this Picture box on frmGroups"
can you tell me how this could be done.  I never thought this is possible to do in VB.  Are you using VB 6?

in relate to your question, why don't you trap the tab key in frmGroups and forward it to the form inside the picturebox.

private sub frmGroups_keydown(...)
      if (keycode = vbkeytab) then
          frmSubForm.Setfocus
          sendkeys "{TAB}"
      end if
end sub
Avatar of nsgonline

ASKER

Thanks for your help "supunr". Yes, this is possible to open a form in a container control like picturebox. I wanted to do something like Frames in HTML. Just like the way MS Outlook works. Here is a simple way to do this...

1. Create a main form (say Form1)
2. Create a Picturebox on Form1, name it MainFrame.
3. Create another form (say Form2) to be opened inside Form1.
4. On top of Form2, declare the following...
       Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
       Dim oldwnd As Long

5. Now, in the Form_Load event of Form2, write the following code...
       oldwnd = SetParent(Me.hwnd, Form1.MainFrame.hwnd)

6. Enter the following code in Form_Unload event...
       SetParent Me.hwnd, oldwnd

This works perfect... Except for a little Tabs problem. I will try your solution, but this is a dirty work. As I have buttons on frmGroups to be accessed using Tab key. But fields are on a sub-form inside the picturebox.
Avatar of DanRollins
nsgonline, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial