Link to home
Start Free TrialLog in
Avatar of Trying_to_Learn
Trying_to_LearnFlag for Canada

asked on

Need to open a form within a form on click

Hi,

I am tring to work on a protoype, and have a widget on the main page on which icons are present. Once the user clicks an icon, another form should show within the same main form, but shouldn't be loaded over the widget.

So basically I want the form to be loaded on the click event within the same main form.

How do i do this in VB6?

Private Sub Command1_Click()
Dim frm As New FRM_NowPlaying
frm.Show (vbModeless)
End Sub

Open in new window

Avatar of Surone1
Surone1
Flag of Suriname image

try just:

Private Sub Command1_Click()
FRM_NowPlaying.Show vbModeless
End Sub
Avatar of Pacane
Pacane

I'm not sure what you're exactly asking for...

If you want to create a child form:
Dim frm As New FRM_NowPlaying
frm.ShowDialog

and if you want your current form to become a new one (I've never tried, but it could be)
Me = frm.Show()
Avatar of Trying_to_Learn

ASKER

I've attached a picture of what I want

I want the Now_Playing form to open within the MainForm and not overlap with the widget and look as if it is within the main form.
hci.png
Instead of an MDI Form I can also make a dialog box, but I will need to make sure that I can implement functionality in this form, same as in a normal form.

Is there a way to maximize the size of the dialog or the MDI form within the main form, without being overlapped by the widget, I want the widget form to be the main form and all other screens to open within the same form, once user closes them it will return to the main window.
You should check out splitcontainers (and instead of a form, you'd use the right panel of the splitcontainer)
You can do this with MDI child forms.  Just position the form in the correct spot when you create it in the Load event, such as attached.  m_frmRequestLog is a form similar to what you have on the left.  m_frmInstructions is a similar form,but sits at the top if it is there.  The new form positions itself to the right of the left hand form and below the top form (if it is there)

    Me.Left = MDI_DBCMain.m_frmRequestLog.Left + MDI_DBCMain.m_frmRequestLog.Width
    If g_intShowInstructions = 1 Then
      Me.Top = MDI_DBCMain.m_frmRequestLog.Top + ParentForm.m_frmInstructions.Height
    Else
      Me.Top = MDI_DBCMain.m_frmRequestLog.Top
    End If

Open in new window

Will I be able to open multiple click events in the split container?

How do I do this in VB6?

Is this in the components tab?
JohnBPrice:

I get an object required error.

My main form is called Form1


Private Sub MDIForm_Load()
Me.Left = MDI_DBCMain.Form1.Left + MDI_DBCMain.Form1.Width
    If g_intShowInstructions = 1 Then
      Me.Top = MDI_DBCMain.Form1.Top + ParentForm.m_frmInstructions.Height
    Else
      Me.Top = MDI_DBCMain.Form1.Top
    End If
End Sub

Open in new window

JohnBPrice: - What is MDI_DBCMain ??

Do I need to add any references?
Avatar of Brook Braswell
do you want your newly opened form to also move with the "Master" form where your buttons are?
if so....
then you could set the form top and left and even size based on the current master form so that the left position is always to the right of the master form.
then if you move the master form ( in the Form_Paint event ) also move the top visible Now_Playing form.


place a Frame object on your calling form.
Name it frPosition and make it invisible
You can use this to position and even size the Now_Playing form.

on Activate of Now_Playing...
me.Top = Master.frPosition.top
me.left = Master.frPosition.left
me.height = master.frposition.height
me.width = master.frPosition.width

if you are using more than one of the Now_Playing forms...
I suggest you have a Global variable called LastForm as a form.
on Activate of Now_Playing - Set LastForm = Me

after...
Dim Frm as New Now_Playing
frm.show vbmodal, Master  ' NOTE IF THIS FORM IS SHOWN MODAL YOU WILL ONLY BE ALLOWED ONE OF THESE AT A TIME
frm.Tag = ( set a unique tag to indicate what this form is showing or what it is )

In the PaintEvent of Master

private sub Form_Paint()
LastForm.Top = Master.frPosition.top
LastForm.left = Master.frPosition.left
LastForm.height = master.frposition.height
LastForm.width = master.frPosition.width
   
end sub

Sorry, MDI_DBCMain is the name  of the MDI parent form, you would use your own parent MDI form name, the "M_xxx" are variables in it to track open forms.  You would need to replace the form names with your own.  In this example, there is always a m_frmRequestLog, but not always a m_frmInstructions.  You could simply refer to the design name of the form if it is always there.  If you refer to the design name of something that may or may not be there, such "frmInstructions.whatever" VB will create an instance of it, which is not what you want, this is why my code tracks g_intShowInstructions to determine if the instructions form is there.  You can also walk the forms collection of the MDI Parent.

Note also that this won't work for moving the minimized icon around (you get an error in vb if you try to move a minimized MDI child), to do that you would have to use SetWindowPlacement and GetWindowPlacement in the WinAPI.

None the less, you should be able to create a couple fairly simply public routines that every child form would call on Load and on Resize.
Brook: I understand the concept of keeping an invisible frame and then making it visible, but that would only allow me to have 1 frame while I am desgning the interaface on the main page, and I will need to make subsequent frames for other windows on the same page as well, which will become confusing while designing...
JohnBPrice: I am a little confused with the MDI forms, I think I dont understand their significance. I have 1 MDI form called FRM_NowPlaying, the main form is not an MDI Form and is called Form1.

I tried playing with the Form Layout and could get a dialog box to fit into the way I want it, and set is as vbmodal...
ASKER CERTIFIED SOLUTION
Avatar of JohnBPrice
JohnBPrice

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
note also that the parent MDI form has some built in functions for stuff you normally need, like tile or cascade all windows, when you close the MDI parent, all the children close, a builtin collection of all the open child windows, etc.
BTW, this is backwards.  You want the main form to be the MDI form, and the "now playing" to be a MDI Child (by setting the MDI Child property)
>> I have 1 MDI form called FRM_NowPlaying, the main form is not an MDI  Form and is called Form1.
Thanks...