• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

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

0
Trying_to_Learn
Asked:
Trying_to_Learn
  • 7
  • 6
  • 2
  • +2
1 Solution
 
Surone1Commented:
try just:

Private Sub Command1_Click()
FRM_NowPlaying.Show vbModeless
End Sub
0
 
PacaneCommented:
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()
0
 
Trying_to_LearnAuthor Commented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Trying_to_LearnAuthor Commented:
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.
0
 
PacaneCommented:
You should check out splitcontainers (and instead of a form, you'd use the right panel of the splitcontainer)
0
 
JohnBPriceCommented:
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

0
 
Trying_to_LearnAuthor Commented:
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?
0
 
Trying_to_LearnAuthor Commented:
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

0
 
Trying_to_LearnAuthor Commented:
JohnBPrice: - What is MDI_DBCMain ??

Do I need to add any references?
0
 
Brook BraswellApplication Development ManagerCommented:
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.


0
 
Brook BraswellApplication Development ManagerCommented:
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

0
 
JohnBPriceCommented:
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.
0
 
Trying_to_LearnAuthor Commented:
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...
0
 
Trying_to_LearnAuthor Commented:
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...
0
 
JohnBPriceCommented:
In VB6, the built in mechanism to support form within a form is to use MDI forms (Multiple Document Interface).  Your application is allowed to use one and only one MDI Form (when you add to a project, you are given the choice to add a form, a MDI form, a module, a class module, etc.)  The MDI form is the one that contains other forms.  For other forms, if you want them contained in the MDI form, you must set the MDI Child property to true.  Whenever you show one of these forms, it will be shown within the projects MDI Form.

If your main form is not an MDI Form, what you are trying to do is simulate windows within windows, which you can do if the built in MDI form support doesn't work for you, but you will have extra work to do to make everything appear as if it were windows within windows.

see http://visualbasic.freetutes.com/learn-vb6/lesson16.html

Note that the parent MDI form can't hold most controls, but you CAN put in a picture box, and then put other controls inside the picture box.  Create a new standard project, add a MDI Form to it, draw a picture box on the MDI form, change the picture box Align property to Align left, and drop some controls in the picture box.  Run it.  The behavior of this simple app is pretty close to what you are trying to do.
0
 
JohnBPriceCommented:
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.
0
 
JohnBPriceCommented:
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.
0
 
JohnBPriceCommented:
Thanks...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 6
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now