How to make it simple - vb.net

My code:
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
PictureBox1.Enabled = False
End Sub
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
PictureBox2.Left = "90"
End Sub
How can I simply change the name of PictureBox1 and PictureBox2?. Example I just need to change their name like:
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
I.Enabled = False
End Sub
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
I.Left = "90"
End Sub
'I change their name to "I"

You can do that from the properties window. All you need to do is:
have the object that you want to change its name changed active by clicking on it.
on the properties window search for (Name) and change it to the name that you want your object to have i.e I but remember that your names should be clear and easy to understand.
Remember that you can not have two different objects the same name in one form you will therefore have to give them different names

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

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

Second form is not loading properly on Visual Builder?

in the first form I have a text box where you can add your name, and then when you click Next window, the second form will pop up saying My name is : Your name . This is great, but how would I be able to change the name of the second form known as OtherForm to my name aswell so that when the second form pops up, on the top left corner my name would appear instead of OtherForm? Here is the code for the first and second form so far.
Main Form code:
Public Class MainForm
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
Public Sub Label1_Click(sender As Object, e As EventArgs) Handles
WindowName.TextChanged
End Sub
Public Sub WindowName_TextChanged(sender As Object, e As EventArgs)
End Sub
Public Sub OffButton_Click(sender As Object, e As EventArgs) Handles
OffButton.Click
Me.Close()
End Sub
Public Sub NextButton_Click(sender As Object, e As EventArgs) Handles
NextButton.Click
OtherForm.NameLabel.Text = WindowName.Text
OtherForm.Show()
End Sub
End Class
Second form known as OtherForm
Public Class OtherForm
Public Sub CloseButton_Click(sender As Object, e As EventArgs) Handles
CloseButton.Click
Me.Close()
End Sub
Public Sub OtherForm_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
Public Sub NameLabel_Click(sender As Object, e As EventArgs) Handles
NameLabel.Click
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles
Label1.Click
End Sub
End Class
Try
OtherForm.Text = WindowName.Text
to set the title of the form. Or you can set the text to whatever you would like. I'm not sure if you mean "my name" or the name you entered.
If you do mean "my name" then you can enter that in the form property for "Text" instead of in code as well.

How to make a listbox automatically update when the source (list) is changed

So I have a listbox with a List as a datasource. What I want is that when I add and remove items from the List, the listbox updates itself.
Right now im able to do it but in a really ugly way. What I do is remove and add the datasource in all the places that I modify the list:
For example:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
formaciones.Add(New ForDias(Formacion, NumericUpDown1.Value))
ListBox2.DataSource = Nothing
ListBox2.DataSource = formaciones
End Sub
This works, but is there any way of telling the Listbox to check again the datasource without resetting it?
Edit:
How I filter:
On the textBox text changed event:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
ListBox2.DataSource = New BindingList(Of Object)((formaciones.Where(Function(i As ForDias) i.Formacion.ToString().Contains(TextBox1.Text))).ToList())
End Sub
You need to bind a "BindingList(of ForDias)"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim formaciones As New System.ComponentModel.BindingList(Of ForDias)
formaciones.Add(New ForDias(Formacion, NumericUpDown1.Value))
ListBox2.DataSource = Nothing
ListBox2.DataSource = formaciones
End Sub