Solved

Need to open a form within a form on click

Posted on 2010-11-09
18
534 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
  • 7
  • 6
  • 2
  • +2
18 Comments
 
LVL 13

Expert Comment

by:Surone1
Comment Utility
try just:

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

Expert Comment

by:Pacane
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Trying_to_Learn
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
JohnBPrice: - What is MDI_DBCMain ??

Do I need to add any references?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 14

Expert Comment

by:Brook Braswell
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now