On first click I'd like to see listbox and some buttons disabled.
On second click I'd like to see that listbox and buttons enabled again.
My current code is:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button2.Click
lstbx_1.Enabled = False
lstbx_2.Enabled = False
outbtn.Enabled = False
Button2.Text = "remove approval"
End Sub
Try this code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
lstbx_1.Enabled = Not (lstbx_1.Enabled)
lstbx_2.Enabled = Not (lstbx_2.Enabled)
outbtn.Enabled = Not (outbtn.Enabled)
If lstbx_1.Enabled = False Then
Button2.Text = "remove approval"
Else
Button2.Text = "Your Text"
End If
End Sub
Related
I'm trying to make it so when the button is pressed, it disables the button and allows you to select the mouse coordinates. (With right click) then enable back the button. How do you detect if button1 was pressed for the if statement while keeping the timer?
If Button1.clicked Then
This is where I need the If statement to detect button1 being pressed.
Private Sub Timer2_Tick(sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Button1.clicked Then
Button1.Enabled = False
If GetAsyncKeyState(2) Then
TextBox1.Text = Cursor.Position.X
TextBox2.Text = Cursor.Position.Y
Button1.Enabled = True
End If
End If
End Sub
Thanks with the help of #the_lotus I found a way around the timer/button issue.
Instead of looking for the button press within the timer statement, you control if the timer is on or off.
Lotus also asked for the reasoning behind the timer. The timer is so the form always looks for a input, not just when the button is pressed.
Private Sub Button1_Click(sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Timer2.Interval = 5
Timer2.Enabled = True
Me.Button1.Text = "Set Posistion 1"
End Sub
Sub Timer2_Tick() Handles Timer2.Tick
If GetAsyncKeyState(2) Then
TextBox1.Text = Cursor.Position.X
TextBox2.Text = Cursor.Position.Y
Button1.Enabled = True
Timer2.Enabled = False
Me.Button1.Text = "Reset Position"
End If
End Sub
I'm Trying To make A button Only clickable once in Vb
I was thinking of this code
Sub B64_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B64.Click
Dim BClick As Integer = 0
If BClick = 0 Then
BClick = 1
'Other instructions
End If
Any Other Ideas!
Also Can I do something so that the button will make a sound when it is clicked ?!
Any Other Ideas!
Thank u
In your click event you can do:
B64.Enabled = False
You can also play a .WAV file on click:
Dim player As New System.Media.SoundPlayer()
player.SoundLocation = path
player.Load()
player.Play()
Just Disable Button
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Button1.Enabled = False
'Do Stuff....
'& Enable it if you want
Button1.Enabled = True
End Sub
you can disable button or any control with this code
by using Button1_Click(Button1, Nothing) or Button1_Click(Button2, Nothing)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim Element As Button = DirectCast(sender, Button)
Element.Enabled = False
'Do Stuff....
'if you want delay use: Threading.Thread.Sleep(500)
Element.Enabled = True
End Sub
I want to know the code to the following illustration.
i have one form with some checkboxs and one button,
screen is here
i've try with this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = True And CheckBox4.Checked = True Then
'when the button is clicked will be the process for moving images
'Like
System.IO.File.Copy(Application.StartupPath + "\File\Pic1.jpg", "D:\File\Pic1.jpg")
End If
End Sub
I was tired with that code, is there a shorter coding ?
for example, if the checkbox1.checked = true and another checkbox not checked then only moving one pict
If I understand the question, you want to copy pictures 1 to 4 if the checkboxes 1 to 4 are checked.
Try this:
Dim SourcePath As string = Application.StartupPath + "\File\"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CopyFile(CheckBox1, "Pic1.jpg")
CopyFile(CheckBox2, "Pic2.jpg")
CopyFile(CheckBox3, "Pic3.jpg")
CopyFile(CheckBox4, "Pic4.jpg")
End Sub
Private Sub CopyFile(CB As CheckBox, FileName As String)
If CB.Checked Then
System.IO.File.Copy(SourcePath + FileName, "D:\File\" + FileName)
End If
End Sub
I've been trying to simulate a cashpoint in visual basic and it's been going okay, I've got buttons from 1-9 and a clear key set up but I removed the code to shorten it for here. I was wondering if there was any alternative ways to make a section of code change when a MsgBox was closed with OK. The section I wish to change specifically is:
If Label1.Text = "Please wait.."
Then
Label1.Text = "Proceed to enter your pin."
End If
which is in the code below, I've tried to use: Threading.Thread.Sleep(5000) but all it does is cause the entire program to freeze until it's done and then carries on to do the whole script. What I really want it to do is change the text in Label1 to what I've already attempted. It might be horribly easy to do but I'm still new to this, so any help would be greatly appreciated!
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim buttonArray = {btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0, btnClear}
For Each button In buttonArray
button.Enabled = False
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim buttonArray = {btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0, btnClear}
barProgress.Increment(5)
If barProgress.Value = 100 Then
For Each Button In buttonArray
Button.Enabled = True
Next
Timer1.Stop()
MsgBox("Please insert your pin into our secure system.")
End If
End Sub
Private Sub btnInsertCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertCard.Click
Timer1.Start()
Label1.Text = "Please wait.."
If btnInsertCard.Text = "Insert Your Card" Then
btnInsertCard.Text = "Please wait.."
End If
If Label1.Text = "Please wait.." Then
Label1.Text = "Proceed to enter your pin."
End If
End Sub
End Class
What I have:
I have two group boxes each with a text box inside. A third text box is placed outside both of the group boxes.
Button 1 is the default accept button on form load.
What I need:
When button 1 is clicked (or enter key is pressed), I need button 2 to become the default accept button.
My problem:
Button 3 becomes the default accept button rather than button 2 in spite of my code.
My code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GroupBox1.Enabled = True
GroupBox2.Enabled = False
Me.AcceptButton = Button1
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show("Button 1 pressed!")
GroupBox1.Enabled = False
GroupBox2.Enabled = True
Me.AcceptButton = Button2
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MessageBox.Show("Button 2 pressed!")
GroupBox1.Enabled = True
GroupBox2.Enabled = False
Me.AcceptButton = Button1
End Sub
End Class
the problem is after you press button 1 button 3 gets focus.
you could fix it by adding code to focus to the button you need in the button 1 click event. "Button2.Focus()" etc..
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show("Button 1 pressed!")
GroupBox1.Enabled = False
GroupBox2.Enabled = True
Me.AcceptButton = Button2
Button2.Focus()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MessageBox.Show("Button 2 pressed!")
GroupBox1.Enabled = True
GroupBox2.Enabled = False
Me.AcceptButton = Button1
Button1.Focus()
End Sub