-
Jan 25th, 2015, 09:28 PM
#1
Thread Starter
Lively Member
[RESOLVED] Navigating Panelled Forms
Hello I am running multiple forms inside a panel.
I only want one maximized form in Panel1 at any one time, so when I go to add another form I need to minimize the current form in Panel1 and move it to Panel2 then add the new Form to Panel1.
Also when I maximize a form from Panel2 I need the current form in Panel1 to be minimized and moved to Panel2.
So only 1 maximized form in Panel1 and all other minimized forms in Panel2.
I have had several goes at this with mixed results and ever increasing complex code so I think I am missing the point somewhere.
Any assistance to get me thinking in the right direction would be appreciated thank you.
_____________________________
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim form2 As New Form2()
form2.TopLevel = False
Me.Panel1.Controls.Add(form2)
form2.Show()
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If Me.WindowState = FormWindowState.Minimized Then
Me.TopLevel = False
Me.Panel2.Controls.Add(Me)
Me.WindowState = FormWindowState.Minimized
End If
End Sub
End Class
_____________________________
Public Class Form2
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Form2_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.TopLevel = False
Form1.Panel2.Controls.Add(Me)
Me.WindowState = FormWindowState.Minimized
End If
End Sub
End Class
_____________________________
-
Jan 26th, 2015, 04:42 PM
#2
Re: Navigating Panelled Forms
Originally Posted by tonyallan8128
So only 1 maximized form in Panel1 and all other minimized forms in Panel2.
I suppose to be OOP correct you'd want to create a class so you can set the main parent form, etc,etc, but just as a concept where form1 is the startup form this should work, though I just used one button, it adds a new form2 then pass it to a sub that moves it into panel1 and maximizes it, all other forms are moved into panel2 and minimized.
Form2 resize calls the same sub and acts the same way...
Code:
Public Class Form1
' add new form
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim frm2 As New Form2()
frm2.TopLevel = False
frm2.Show()
' move & maximize this form to panel1,
' move & minimize all other forms to panel2.
MaxiForm(frm2)
End Sub
' maximize, minimize and move forms to panels
Public Sub MaxiForm(maxForm As Form)
For Each f As Form In Application.OpenForms
If f IsNot Me Then
If f.Equals(maxForm) Then ' if form passed to sub then max it, move to panel1
f.Parent = Panel1
f.WindowState = FormWindowState.Maximized
Else ' move and minimize all other forms to panel2.
f.Parent = Panel2
f.WindowState = FormWindowState.Minimized
End If
End If
Next
End Sub
End Class
Code:
Public Class Form2
Private Sub Form2_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Maximized Then
If Not Me.Parent Is Form1.Panel1 Then ' if not already in form1.panel1 then move it.
Form1.MaxiForm(Me)
End If
ElseIf Me.WindowState = FormWindowState.Minimized Then
Me.Parent = Form1.Panel2
Me.WindowState = FormWindowState.Minimized
End If
End Sub
End Class
-
Jan 26th, 2015, 05:30 PM
#3
Re: Navigating Panelled Forms
Oh what the heck, here is my attempt at it.
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AddForm("1", True)
AddForm("2", False)
AddForm("3", False)
End Sub
Private Sub AddForm(ByVal text As String, ByVal maximized As Boolean)
Dim f As New Form
f.Text = text
f.TopLevel = False
If maximized Then
f.WindowState = FormWindowState.Maximized
f.Parent = panelMax
Else
f.WindowState = FormWindowState.Minimized
f.Parent = panelMin
End If
f.Show()
AddHandler f.SizeChanged, AddressOf Form_SizeChanged
End Sub
Private Sub Form_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim f As Form = DirectCast(sender, Form)
RemoveHandler f.SizeChanged, AddressOf Form_SizeChanged
Select Case f.WindowState
Case FormWindowState.Maximized
If panelMax.Controls.Count > 0 Then
DirectCast(panelMax.Controls(0), Form).WindowState = FormWindowState.Minimized
End If
f.Parent = panelMax
f.WindowState = FormWindowState.Maximized
Case FormWindowState.Normal, FormWindowState.Minimized
f.Parent = panelMin
f.WindowState = FormWindowState.Minimized
End Select
AddHandler f.SizeChanged, AddressOf Form_SizeChanged
End Sub
End Class
-
Jan 31st, 2015, 08:44 AM
#4
Thread Starter
Lively Member
Re: Navigating Panelled Forms
Thank you both these answers have got me going again. lol one solution creates more questions.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|