Trying to enter a name in a textbox, hit ok, and have that form close and pass the info to another forms label - vb.net

***THE CODE FROM THE FIRST WINDOW GOES INTO A TEXT BOX AND YOU HIT THE BUTTON HERE.
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Me.Close()
End Sub
***THE CODE ON THE FORM WHERE I WANT THE INFO TO BE PLACED IS HERE.
Private Sub Loan1Form_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.lblCompanyName.Text = DataEntryForm.txtCompanyNameInput.Text
End Sub
Anyway's that's what I found on a youtube video and im having trouble getting it to work. Any help would be appreciated.
Thanks.

Pass the data to an instance of the form:
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Dim f As New OtherForm
f.lblCompanyName.Text = txtCompanyNameInput.Text
f.Show()
Me.Close() 'make sure this form is not the one that closes the app if it closes
End Sub

Related

Enable/Disable a form while in an another form

I'm trying to figure out how to disable my form(Form1.vb) without hiding it then enabling it after I'm done with the other form(Form2.vb).
I've searched on youtube but it says C#. I've tried it but somehow it was indicated as an error in VS 2015. I tried messing around with the syntax because I really can't figure it out. The syntax that I have tried is "LandingForm.ActiveForm.Owner.Enabled = True".
Indicated below are the codes of my system. The first one is form1.vb/LandingForm.vb and the second one is form2.vb/AcctSettings.vb.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Enabled = False
AcctSettings.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
LandingForm.ActiveForm.Owner.Enabled = True
Me.Hide()
End Sub
Am I missing something? Can somebody help?
On your form1 just have a simple line like
Form2.Show()
wherever/however you wish to open the other form (button etc.)
then in the code for that form2 in the formload handeler have
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Enabled = False
End Sub
This will keep form1 open but basically grey it out.
Then have a simple button click like so to have access to form 1.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form1.Enabled = True
End Sub
And you are done! And if you wish just add another button or a IF statement to the button2 sub and say form1.enabled = false if you want to be able to enable/disable etc.
To enable/disable your userform :
To disable your userform you will need yo enable it before :
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Enabled = True
Form1.Enabled = False
End Sub
To disable it will be easier you just got to set your userform.enabled as False
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form2.Enabled = True
End Sub
If you want to close your userform useroform.Unload might be the solution.
In your code it would be like this :
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Enabled = False
AcctSettings.Show()
form1.Unload
End Sub
and
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
LandingForm.ActiveForm.Owner.Enabled = True
Me.Hide()
form2.Unload
End Sub
an other option is to Hide your user form : it will just hide the userform and will not release the objects and variables from the memory. Where as Unload method will release the objects and variables from the memory.
UserForm1.Hide
To conclude : Hide method will be used when we want to hide the form temorarly and to show after sometime to the user. Where as unload will be used when it completes the task.
Note that this is YourUserForm_Name.Unload

Passing strings between forms while both forms are are being shown on screen

Hello to stackoveflow community members.!
I am reading threads from stackoverflow from past 6 months and which was really helpful for me. I never get stuck to anything where i need to write my own question here.
Currently i am working on visual studio 2015 with window based .net application.
I am having multiple forms in my application. I am loading a form into another form through panel control.
Say i have a form1 which is main form and form2 which i have opened main form using panel control.
When i am opening my form1 as startup form the data transfer is taking place. But when i am using another form say form3 for login page as startup the data transfer is not working between form1 and form2.
Could some please help.!!
Please find example code as below.
enter image description here
Number of Forms - 3,
Form3 as Login Form,
Form1 as Main Form,
Form2 as Entry Form,
Code for Form3-==========
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim form1 As New Form1
form1.Show()
Me.Hide()
End Sub
Code for Form1-===========
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RichTextBox1.Text = "Hello"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim f As Form
f = Form2
f.TopLevel = False
f.WindowState = FormWindowState.Normal
f.FormBorderStyle = FormBorderStyle.None
Me.Panel1.Controls.Add(f)
f.Dock = DockStyle.Fill
f.Show()
End Sub
Code for Form2-=========
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form1.RichTextBox1.Text = Me.TextBox1.Text
End Sub
As suggested by 'Preciousbetine', i have removed new instance for form1. Application is working as desired.
Thank you so Much!!!
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form1.Show()
Me.Hide()
End Sub

Vb.net : How can i Click 2 buttons at the same time?

i'm just a beginner here, please help me to solve my problem, and actually i didn't have a code yet for this.
i have a 2 flow out panel and have a buttons. the Menu button in the upper side and the Menu button in the bottom side. how can i click them at the same time?
No you cannot do that, but there is a way to achieve your problem,
Do something like this,
This is only a suggestion..
Private Sub btnMenuUpper_Click(sender As Object, e As EventArgs) Handles btnMenuUpper.Click
'Code Here
End Sub
That's the first button and that will be activate also the second button.
Private Sub btnMenuBottom_Click(sender As Object, e As EventArgs) Handles btnMenuBottom.Click
'Code Here
End Sub
And just call the btnMenuBottom to btnMenuUpper.
Private Sub btnMenuUpper_Click(sender As Object, e As EventArgs) Handles btnMenuUpper.Click
'Code
btnMenuBottom_Click(sender, e)
End Sub
This should work
Private Sub btn1_click(sender as object, e as EventArgs) handles btn1.click
btn2.performclick
end sub

Is there a Form event like "Shown" but runs the code every time it is displayed instead of the just first time?

Just noticed in one of my programs that the form event Shown only runs the code when the form is first displayed. Every other time after that it does not run the code. Is there a form event that does what shown does, but every time it is displayed instead of just the first? Or is there a way to get around it? This is the exact same for the Load event too.
Thanks heaps, appreciate any response.
I just tested with this in Form1:
Private f2 As New Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
f2.Show()
End Sub
and this in Form2:
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MessageBox.Show("Form2_Load")
End Sub
Private Sub Form2_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged
If Visible Then
MessageBox.Show("Form2_VisibleChanged")
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Hide()
End Sub
and it worked exactly as expected. Every time I clicked Button1 in Form1, Form2 was displayed. The first time I saw messages for "Form2_Load"and "Form2_VisibleChanged" and on subsequent occasions on for "Form2_VisibleChanged".

How to open up a form from another form in VB.NET?

This I thought would be easy. I have not used VB.NET all that much, and I am trying to open up a form from a button click. The form will not show and I get a null exception error.
What is wrong with the code?
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Dim A
A = AboutBox1
A.Show()
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) _
Handles Button3.Click
Dim box = New AboutBox1()
box.Show()
End Sub
You can also use showdialog
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) _
Handles Button3.Click
dim mydialogbox as new aboutbox1
aboutbox1.showdialog()
End Sub
You could use:
Dim MyForm As New Form1
MyForm.Show()
or rather:
MyForm.ShowDialog()
to open the form as a dialog box to ensure that user interacts with the new form or closes it.
You may like to first create a dialogue by right clicking the project in solution explorer and in the code file type
dialogue1.show()
that's all !!!