Solved

Resize and cascade

Posted on 1998-08-10
7
268 Views
Last Modified: 2010-04-30
I created 2 type of mdichild form :
A form :  should always stay at the left side of the mdiform
B form :  stays beside A form.
That means,when A resize, B will resize too so that both can occupy and share the view space.
There are times where only A form appear.
Some time only B form appear and B form can be many (cascading)

This is exactly like the VB5 developing environment.

0
Comment
Question by:chualk
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:waty
Comment Utility
you should set the position and size of each form in resize event of each form.

Define globally 2 variables :
  Global FormA    as Form
  Global FormB    as Form

in the Form_Load of each form do the following :
  Set FormX = new Form
  Set FormX = Me

in the Form_UnLoad of each form do the following :
  Set FormX = nothing

In the risize event, use the 2 variable to set the correct size and position

  FormB.Width = MDIMain.Width - FormA.Width
  FormB.Left = FormA.Left + Form1.Height

.

Put all the need code for you here


0
 
LVL 1

Author Comment

by:chualk
Comment Utility
Waty :

Please note that there are some situation that only form A or FormB will load.
The resize_event will activate everytime a form is loaded.
So there will be a run time error because another form is not found.
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
you have to test if the form contains valid information :

if FormB is Nothing then
   ' *** FormB is not loaded
Else
   ' *** Do work on FormB
End If
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:chualk
Comment Utility
It doesn;t work well
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
This is the best solution. I have used it in some projects.

Tell what's wrong
0
 
LVL 1

Author Comment

by:chualk
Comment Utility
Waty:

Your way is not wrong but somehow there are some problems.These are the code i test. Point out if i misunderstood your code or really cannot overcome this.


Global form1 As Form
Global form2 As Form

'Code for form2

Private Sub Form_Load()

   Set formx = New form2
   Set formx = Me
End Sub

Private Sub Form_Resize()
 If Not form1 Is Nothing Then
    form2.Width = MDIForm1.Width - form1.Width
    form2.Left = form1.Left + form1.Width
 End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
      Set formx = Nothing
End Sub

About the same code pasted on the form1.

IF i unload form1 and resize, form2 reload.
 
0
 
LVL 14

Accepted Solution

by:
waty earned 70 total points
Comment Utility
I have tested the following code and works well :
If you give me your e-mail, I can send you the test project.

Add into your MDI (create 2 menus)
Private Sub m1_Click()
frm1.Show
End Sub

Private Sub m2_Click()
frm2.Show
End Sub

Private Sub MDIForm_Load()

   Set form1 = Nothing
   Set form2 = Nothing

End Sub

***************************************************************

Add into form1 :
Private Sub Form_Load()
   Set form1 = Me
End Sub

Private Sub Form_Resize()
 If Not form2 Is Nothing Then
    Me.Width = MDIForm1.Width - form2.Width
    Me.Left = form2.Left + form2.Width
 End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
   Set form1 = Nothing
End Sub

***************************************************************

Add into form2:
Private Sub Form_Load()
   Set form2 = Me
End Sub

Private Sub Form_Resize()
 If Not form1 Is Nothing Then
    Me.Width = MDIForm1.Width - form1.Width
    Me.Left = form1.Left + form1.Width
 End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
   Set form2 = Nothing
End Sub

***************************************************************

Add in a bas file

Global form1 As Form
Global form2 As Form

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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