How can I manage other forms under the main form? - vb.net

I am trying to manage form2 to form9 under the main form1 in my project.
form1 contains a menustrip and from that I call the other forms with code
form3.show()
The problem is when I minimize form1 the other forms still stand alone and I must minimize all forms individually
I want one main form - form1 - that I can use to open other forms under their windows.
So form1 minimize than all other forms also minimize.

What you could do is work with the tabcontrol.
U put a tabcontrol on your mainForm and everytime u wanna open a new form u just add that form to a tabcontrolpage.
The code would look like this
Dim frm = New form1
Dim page = New C1DockingTabPage
page.Text = frm.Text
frm.ws_Employee_UID.Text = ws_Employee_UID.Text
frm.TopLevel = False
frm.FormBorderStyle = BorderStyle.None
frm.ControlBox = False
page.Controls.Add(frm)
Me.C1DockingTab1.TabPages.Add(page)
frm.Show()
page.Show()
or like said u could learn MDI, but i prefer the TabControl.

Related

How to give focus to the new instance of a form?

I've a program in vb .net with a form named Form1. The form has button when I click on the button a dialog window appears. The dialog window has two buttons OK and Cancel. When the OK button is clicked a new instance of Form1 is created and the new instance is shown. See below code.
Private Sub ButtonOK_Click(...) Handles ButtonOK.Click
Dim frm1 As New Form1
frm1.Show()
End Sub
The problem is when a new Form1 is created by the above code, the previously created Form1 gets focused and the newly created Form1 looses focus. But I want the newly created (latest) Form1 to get the focus. How do I do it?
I have an application that I need to force the user to input information on a new form before proceeding. You can force the new form to show on top and give it focus by doing the following.
Dim frm1 = New Form1()
frm1.Show()
frm1.WindowState = FormWindowState.Normal
frm1.BringToFront()
frm1.TopMost = True
frm1.Focus()

vb.net: Using a Button on a Form to open another form, doesn't work

I encounter the following scenarios when I try to use 2 forms. My workflow is as follows:
(1) Load Form1.
(2) A click on button1 on Form1 closes Form1 and opens Form2.
Solution A: If I use the following code:
Dim oForm As New Form2
oForm.ShowDialog()
Me.Close()
Then Form1 will be under Form2 (Form1 still opens).
Solution B: If I use the following code:
Dim oForm As New Form2
oForm.Show()
Me.Close()
Then Form1 closes and Form2 opens, but Form1 is not on the top layer.
I have looked through the solutions for this, most propose solution B, but for me, both solutions won't work the way I want. Can anybody tell me the reason?
Try
Dim oForm as New Form2
oForm.Show()
and on Load event of form2
Form1.Hide()
Use form.bringtofront() if you want to see the opening Form in the front, I m little confused though about what you are trying to do
Try doing it this way:
Dim oForm As New Form2()
Me.Hide()
oForm.ShowDialog()
Me.Close()
I suspect your are building a log-in dialogue... if so, or something similar, try this..
Open your main form first... (Form 2), have form2 showdialog (modally) form1... this will put form1 on top of form2.
Add a property to form 1, that gets set depending on what happens there.. sucessfull login for instance.
Close form 1 from its own methods... (after successful authentication), set the property before closing.
On form2, read this property of form1, and then dispose form1, and decide what to do... if unsuccessful login, show the login form again, end app. If successful, just gracefully exit out of the method that showed form1. Your form 2 is now the only form open.
Start with Form2
Form2_load
dim f1 as new form1
f1.showdialog
if f1.someproperty = somevalue then
' do something here, for instance, pop the form again, if you did not get what you were lookign for...
end if
'gracefully let the function end and form2 is now the only open form..
'dispose of form1. form1's close call does not dispose it, because it was opened modally. (showdialog)
f1.dispose
f1 = nothing
in form1, depending on what you are doing, set the custom property and call me.close, this will exit the form, and run the next code in form2.
try this:
Dim oForm As New Form2
oForm.Show()
Me.Visible = False
You would to close your first form and this close your program. If you set him on invisible, he is not closed.
Just go to form2 and write the Form1.hide() . I tried to close form1 but it closed my whole program.
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Hide()
End Sub
End Class

Working With multiple instance of a windows form in vb.net

I have three forms (form1, form2, form3) in a windows application using vb.net
form1 has a button (button1). Onclick of button1, I want to open form2 in such a way that it can also open multiple times. I achieved this with the code below:
Dim myForm As New Form2
myForm.Show()
Now form2 has a button (button2), and a label (label1). Onclick of button2, I want to open a single instance of form3 a dialog, so I have the code below:
form3.showdialog()
form3 has a textbox (textbox1).
My problem is that I want when I fill textbox1, I want the value to appear in label1 of form2 that opened the form3, I tried the code below, but it did not work:
form2.label1.Text = textbox1.Text
I need to update form2 (the last active one) once form3 has been closed
Can anybody help me out please?
When you go to show the Form3 as a dialog, you should be able to do:
Dim f3 As New Form3
f3.ShowDialog()
Me.label1.Text = f3.textbox1.Text 'Copy the value out of the dialog

How to pass the value to current active form

Using VB.Net
I have main form name as form1 and popup form name as form2
Form1
tab button - for creating mulitple copy of form1 at runtime...
Creation of mulitple from1 at runtime code
form1 code
Dim mEntryForm As form1
mEntryForm = New form1
mEntryForm.Show()
The above code is creating a same copy of form1 at runtime.
Now i want to pass the value from popup form to current activeform
Code for sending the value to form1 from popup form (form2)
form2code
form1.textbox1.text = "100"
The above code is going to form1 textbox, instead of active form (mentryform)
How to solve this problem.
Need Vb.net code help
Although I totaly agree with the comments about your question I ll try to give you a solution
Add a property to your Form2
name smtng like ActiveForm1 as form1
now because I haven't understand completey your concept:
-> if Form2 is a ShowDialog form then you cannot change the active form1.
You need to set the property ActiveForm1
dim frm2 as new form2
frm2.ActiveForm1=me
frm2.ShowDialog
->if Form2 is not a ShowDialog that means that you can change the active form1
then you need to add this lines of code when a form1 is activated
frm2.ActiveForm1=me
Now in form2:
me.ActiveForm1.textbox1.text = "100"
I hope that I helped you.

VB.NET z-order (ordering forms with ownership)

I have situation when opening several "owned" forms from my form.
Dim f As New ownedform
With f
.Owner = Me
.Show()
End With
That works OK.
But I have a question.
Can I somehow by pressing some button on "owner" or "owned" form to get "owner" form to become a toplevel and pop over "owned" forms?
I try a simplest with ".BringToFront" but that don't work.
BringToFront only for controls to set z-order .
but you can make that . first write this code in form1
Me.Hide()
Dim frm As New form2
frm .ShowDialog()
thien write this code in form2
Me.Hide()
Dim frm As New form1
frm .ShowDialog()