Enable/Disable a form while in an another form - vb.net

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

Related

VB.net One sub for many events

I'm working on a function in VB.Net where a user can select a supplier from a list.
The idea is that the user will filter the list until the right supplier is visible in a datagridview
the user can then either double click on the row header, the cell content or select a supplier and then click an OK button
I am wondering though, how do I avoid building one Sub for each of the above three events, Can I create one sub that catches all three events?
Private Sub supplierSearchOkButton_Click(sender As Object, e As EventArgs) Handles supplierSearchOkButton.Click
initiativeForm.supplierConcatTextBox.Text = supplierSearchDataGridView.SelectedRows(0).Cells(3).Value.ToString()
Me.Close()
End Sub
Private Sub supplierSearchDataGridView_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles supplierSearchDataGridView.CellContentDoubleClick
initiativeForm.supplierConcatTextBox.Text = supplierSearchDataGridView.SelectedRows(0).Cells(3).Value.ToString()
Me.Close()
End Sub
Private Sub supplierSearchDataGridView_RowHeaderMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles supplierSearchDataGridView.RowHeaderMouseDoubleClick
initiativeForm.supplierConcatTextBox.Text = supplierSearchDataGridView.SelectedRows(0).Cells(3).Value.ToString()
Me.Close()
End Sub
Personally, I would go with the extra method option mentioned in the comments but, if you want to, you should be able to do this:
Private Sub SetSupplier(sender As Object, e As EventArgs) Handles supplierSearchOkButton.Click,
supplierSearchDataGridView.CellContentDoubleClick,
supplierSearchDataGridView.RowHeaderMouseDoubleClick
initiativeForm.supplierConcatTextBox.Text = supplierSearchDataGridView.SelectedRows(0).Cells(3).Value.ToString()
Me.Close()
End Sub
or even this:
Private Sub SetSupplier() Handles supplierSearchOkButton.Click,
supplierSearchDataGridView.CellContentDoubleClick,
supplierSearchDataGridView.RowHeaderMouseDoubleClick
initiativeForm.supplierConcatTextBox.Text = supplierSearchDataGridView.SelectedRows(0).Cells(3).Value.ToString()
Me.Close()
End Sub
If you're not using any properties of the other e parameters then you can use the most general EventArgs for all three events and if you're not using the parameters at all then you can ditch them altogether. I didn't test this specifically but I'm fairly sure both will work.

I have multiple panels on same form and I want Passing a value between 2 panel

I have multiple panels on the same form and I want Passing a value between 2 panels
I want to enter Username in the first panel and Show as Label in next panel
please not in between 2 Form but 2 Panels.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Guna.UI.Lib.GraphicsHelper.ShadowForm(Me)
End Sub
Private Sub GunaButton1_Click(sender As Object, e As EventArgs) Handles GunaButton1.Click
pnLogin.BringToFront()
GunaTransition1.Hide(pnLogin)
End Sub
Private Sub GunaButton2_Click(sender As Object, e As EventArgs)
End Sub
Private Sub GunaGradientButton2_Click(sender As Object, e As EventArgs)
End Sub
Private Sub GunaTextBox1_Click(sender As Object, e As EventArgs) Handles GunaTextBox1.Click
End Sub
End Class
If all the controls are in the same Form, then the container they are within is irrelevant.
The code would look something like this:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = TextBox1.Text
End Sub
You need to change the control names to what you have on your form for the Button, TextBox and Label.
You can simply declare the variable in form class scope and use it! can you explain more details?
Update:
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
Lable.text = TextBox.text
EndSub

In Visual Studio 2013, can the button be hard coded to play a video from a known path?

I have created a simple media player using VB in Visual Studio 2013. My requirement is: just by pressing a button, I need to play the video file available at a fixed path (using the OpenFileDialog I have fixed the path). E.g. pressing a button named 'A' should play a file from 'C:/Playlists'
How can this be done? I can share my current code if needed. I'm new to VB.
Code:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
With OpenFileDialog1
.Filter = "MPEG-4|*.mp4"
.ShowDialog()
TextBox1.Text = .FileName
End With
AxWindowsMediaPlayer1.URL = (OpenFileDialog1.FileName)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
AxWindowsMediaPlayer1.Ctlcontrols.pause()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop()
End Sub
Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
AxWindowsMediaPlayer1.settings.volume = TrackBar1.Value
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AxWindowsMediaPlayer1.settings.volume = 20
End Sub
End Class
I need buttons named A,B,C etc like play, pause which i already have. On pressing button A should play 'file_A.mp3' from 'C:\Playlist'
AxWindowsMediaPlayer1.URL = "C:\Playlist\file_A.mp3"
AxWindowsMediaPlayer1.Ctlcontrols.play()

result of a modal form in vb.net

I create a form 'frmX' and i call it as a modal form :
res = frmX.ShowDialog()
This form has 3 buttons, Abort(3), Retry(4) and Ignore(5), but when the form opens, all the buttons on the first click return 2.
I don't know why this occurs--all of the buttons has their property DialogResult right.
*Private Sub btnIgnorar_Click(sender As Object, e As EventArgs) Handles btnIgnorar.Click
btnIgnorar.DialogResult = DialogResult.Ignore
End Sub
Private Sub btnAbortar_Click(sender As Object, e As EventArgs) Handles btnAbortar.Click
btnAbortar.DialogResult = DialogResult.Abort
End Sub
Private Sub btnReintentar_Click(sender As Object, e As EventArgs) Handles btnReintentar.Click
btnReintentar.DialogResult = DialogResult.Retry
End Sub*
Can someone help me?
Could do with seeing a bit more context, but the following should do what I think you want:
Private Sub btnIgnorar_Click(sender As Object, e As EventArgs) Handles btnIgnorar.Click
DialogResult = DialogResult.Ignore
Close
End Sub
This will close the dialog and return the associated result code to the caller. As to the original code, it seems a bit strange setting the values in the buttons click handlers?
The error comes from the fact that you set the DialogResult of the buttons. You must set the DialogResult of the form !
You actually have more than one option.
Option 1 : Set the Form.DialogResult
Private Sub btnIgnorar_Click(sender As Object, e As EventArgs) Handles btnIgnorar.Click
Me.DialogResult = DialogResult.Ignore
End Sub
Private Sub btnAbortar_Click(sender As Object, e As EventArgs) Handles btnAbortar.Click
Me.DialogResult = DialogResult.Abort
End Sub
Private Sub btnReintentar_Click(sender As Object, e As EventArgs) Handles btnReintentar.Click
Me.DialogResult = DialogResult.Retry
End Sub
Option 2 : Set the Button.DialogResult
Public Sub New()
InitializeComponents()
'Your init code here
'...
'By setting the buttons DialogResults, you don't even have to handle the click events
btnIgnorar.DialogResult = DialogResult.Ignore
btnAbortar.DialogResult = DialogResult.Abort
btnReintentar.DialogResult = DialogResult.Retry
End Sub
'However, if you need to do some stuff before closing the form, you can
Private Sub btnAbortar_Click(sender As Object, e As EventArgs) Handles btnAbortar.Click
'Do some stuff
'You don't need the following line, as it will be done implicitly
'Me.DialogResult = DialogResult.Abort
End Sub

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

***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