make label update on file directory change (visual basic) - visual-studio-2010

When I use an OpenFileDialog, and select a file and click open etc, etc...
I want a label on the same form to automatically update with the directory path. At the moment I have this working, However the label updates on click, not automatically on the directory change.
CODE:
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
Label4.Text = OpenFileDialog2.FileName
End Sub
Cna I change the "Label4_Click" to something else for an auto update?

How are you displaying the OpenFileDialog? You need to update the Label from there!...
Something like:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If OpenFileDialog2.ShowDialog = Windows.Forms.DialogResult.OK Then
Label4.Text = OpenFileDialog2.FileName
End If
End Sub

Related

visual basic and microsoft access database connection

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Database4DataSet.Table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Database4DataSet.Table1)
End Sub
Private Sub BtnPrevious_Click(sender As Object, e As EventArgs) Handles BtnPrevious.Click
Table1BindingSource.MovePrevious()
End Sub
Private Sub btnfirst_Click(sender As Object, e As EventArgs) Handles btnfirst.Click
Table1BindingSource.MoveFirst()
End Sub
Private Sub BtnNext_Click(sender As Object, e As EventArgs) Handles BtnNext.Click
Table1BindingSource.MoveNext()
End Sub
Private Sub BtnLast_Click(sender As Object, e As EventArgs) Handles BtnLast.Click
Table1BindingSource.MoveLast()
End Sub
Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
Table1BindingSource.AddNew()
End Sub
Private Sub btndelete_Click(sender As Object, e As EventArgs) Handles btndelete.Click
Table1BindingSource.RemoveCurrent()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Me.Validate()
Me.Table1BindingSource.EndEdit()
Me.Table1TableAdapter.Update(Me.Database4DataSet)
MsgBox("Your information has been saved successfully")
Catch ex As Exception
MsgBox("Please try again")
End Try
End Sub
Hi i am trying to create a simple vb application that connects to a Microsoft access database that stores basic information of student name, id number and result. my code is working to an extent but when i run the program and add new records the new data i entered saves no problem and i can see while the program is running but when i stop de bugging and start de bugging again the new information i added to the database the last time doesn't appear. only the information that i inputted originally into the database through the access file show up. any info or help would be appreciated.

Visual Basic 2010 Express - How do you switch back and forth between two images that are on top of each other?

I really need some help with this dilemma.
I have two pictures of a light bulb. In one picture the light bulb is shining brightly and in the other it’s turned off. I’m supposed to overlap these pics and make it turn on and off by clicking on the image but I just can’t figure out the code for it. How do you toggle between these images? I am not allowed to use a button to do this. I've got to click on the pic to change it. Please help! Link below as I do not have enough rep to post actual images yet.
http://i1293.photobucket.com/albums/b598/BentoBoy1/ScreenHunter_02Sep202252_zps75800aea.png
Public Class Form1
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
'Close the program
Me.Close()
End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'Print the form in the print preview window
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Turn the light bulb on.
MessageLabel.Text = "Turn on the light"
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MessageLabel.Click
'Display different messages when the light bulbs are clicked.
End Sub
Private Sub RedRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedRadioButton.CheckedChanged
'Set the MessageLabel text to Red.
MessageLabel.ForeColor = Color.Red
End Sub
Private Sub BlackRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlackRadioButton.CheckedChanged
'Set the MessageLabel text to Black.
MessageLabel.ForeColor = Color.Black
End Sub
Private Sub BlueRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlueRadioButton.CheckedChanged
'Set the MessageLabel text to Blue.
MessageLabel.ForeColor = Color.Blue
End Sub
Private Sub GreenRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GreenRadioButton.CheckedChanged
'Set the MessageLabel text to Green.
MessageLabel.ForeColor = Color.Green
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgrammedByLabel.Click
'Programmed by me.
End Sub
Private Sub ColorsGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorsGroupBox.Enter
'Group of different colors.
End Sub
Private Sub NameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameTextBox.TextChanged
'Name field.
End Sub
Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LightOnPictureBox.Click
'Light bulb is on.
LightOnPictureBox.Image = My.Resources.lighton
MessageLabel.Text = "Thanks for turning me on, " & NameTextBox.Text
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LightOffPictureBox.Click
'Light bulb is off.
LightOffPictureBox.Image = My.Resources.lightoff
MessageLabel.Text = "Thanks for turning me off, " & NameTextBox.Text
End Sub
Private Sub NameLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameLabel.Click
'Name label.
End Sub
End Class
Firstly, i think that you should take a look here in order to understand the way images comparisson takes place. Secondly, the proper event to change the picture is the PictureBox.Click...
The code should be like the following one:
Public Class Form1
Dim imageBulbOff As Image = My.Resources.BulbOff
Dim imageBulbOn As Image = My.Resources.BulbOn
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = imageBulbOff
End Sub
Private Sub PictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox1.Click
If PictureBox1.Image Is imageBulbOff Then
PictureBox1.Image = imageBulbOn
Else
PictureBox1.Image = imageBulbOff
End If
End Sub
End Class

how to put a number in a text box using a button in visual basic application forms

I am trying to make a calculator on visual basic application forms and I have most of the codes sorted. How do I make it so when I press the number button, it puts the number in the text box. It also needs to be able to work so if I pressed 1 then 2 then 3, it appears a 123.
Just set the SelectedText() property of the TextBox to the Text() property of your button.
For example:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
TextBox1.SelectedText = Button1.Text
TextBox1.Focus()
End Sub
If you make all the buttons fire the same handler, then it becomes:
Private Sub AllButtons_Click(sender As System.Object, e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, _
Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button0.Click
Dim btn As Button = DirectCast(sender, Button)
TextBox1.SelectedText = btn.Text
TextBox1.Focus()
End Sub

Where to add code?

I am just starting out with windows forms and I am making a button with a mouseover image change (I know I should probably wait with this untill later) and I found this webpage that describes it.
How to change button background image on mouseOver?
and my current code looks like this
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
But I am not sure about where to add the code that is in the link. It gives me error anywhere I put it.

visual basic 2010 copy paste subroutine

I am trying to write 2 simple subroutines in VB 2010 that could be used with toolstripbutton contorls for multiple textboxes in a form. I know simple copy paste could be done using the textbox1.Copy() and TextBox1.Paste() methodes. What i am trying to do is write a common subroutine which could be used on any textboxes in the form not just one particular textbox.
My codes are below, I know there are errors in it, just wondering how it could be achieved. Any help would be highly appreciated. Thanks.
Public Class Form1
Private Sub copytext()
Dim txt As Control
If TypeOf txt Is TextBox Then
Clipboard.Clear()
Clipboard.SetText(txt.SelectedText)
End If
End Sub
Private Sub pastetext()
Dim txt As Control
If TypeOf txt Is TextBox Then
txt.Text = Clipboard.GetText
End If
End Sub
Private Sub mnuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCopy.Click
Call copytext()
End Sub
Private Sub mnuPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPaste.Click
Call pastetext()
End Sub
End Class

Resources