Solved

Need to open a form within a form on click

Posted on 2010-11-09
18
540 Views
Last Modified: 2012-05-10
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
Comment
Question by:Trying_to_Learn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
  • +2
18 Comments
 
LVL 13

Expert Comment

by:Surone1
ID: 34095516
try just:

Private Sub Command1_Click()
FRM_NowPlaying.Show vbModeless
End Sub
0
 
LVL 2

Expert Comment

by:Pacane
ID: 34095522
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
 

Author Comment

by:Trying_to_Learn
ID: 34095706
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:Trying_to_Learn
ID: 34095726
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
 
LVL 2

Expert Comment

by:Pacane
ID: 34095858
You should check out splitcontainers (and instead of a form, you'd use the right panel of the splitcontainer)
0
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 34096317
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
 

Author Comment

by:Trying_to_Learn
ID: 34096334
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
 

Author Comment

by:Trying_to_Learn
ID: 34096598
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
 

Author Comment

by:Trying_to_Learn
ID: 34096616
JohnBPrice: - What is MDI_DBCMain ??

Do I need to add any references?
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34096619
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
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34096702
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
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 34096757
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
 

Author Comment

by:Trying_to_Learn
ID: 34096847
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
 

Author Comment

by:Trying_to_Learn
ID: 34096864
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
 
LVL 16

Accepted Solution

by:
JohnBPrice earned 500 total points
ID: 34097001
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
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 34097047
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
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 34097062
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
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 34097328
Thanks...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month6 days, 19 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question