button.click is not a property, it's an event handler which doesn't return anything. your program can call the event handler from anywhere, just pass it the two arguments.
Ancient Dragon
Achieved Level 70
32,118 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,575
Skill Endorsements: 69
Perhaps use a checkbox with a button appearance instead?
Public Class Form1
Private WithEvents chkButton As New CheckBox _
With {.Appearance = Appearance.Button, _
.CheckState = CheckState.Unchecked, _
.Location = New Point(10, 10), _
.Size = New Size(150, 25), _
.TextAlign = ContentAlignment.MiddleCenter, _
.Text = "I'm really a checkbox", _
.Parent = Me}
Private Sub chkButton_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkButton.CheckedChanged
If chkButton.Checked Then
MsgBox("I'm Depressed")
Else
MsgBox("I'm Up")
End If
End Sub
End Class
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418
Solved Threads: 148
Skill Endorsements: 13
I think what you want is button1.PerformClick(); This will trigger the button click event from anywhere in your code. I'm pretty sure the click event handler subroutine is a must. If you need to record the status of the button click a simple boolean in the click handler routine can handle that.
tinstaafl
Nearly a Posting Virtuoso
1,312 posts since Jun 2010
Reputation Points: 341
Solved Threads: 227
Skill Endorsements: 14
In your code where you want to fire the button click, simple enter this statement,Button1.PerformClick(), and the code in the Button1_Click event handler will execute.
tinstaafl
Nearly a Posting Virtuoso
1,312 posts since Jun 2010
Reputation Points: 341
Solved Threads: 227
Skill Endorsements: 14
buttons don't have a boolean property that works like that. You might have to create your own boolean variables that are toggled on and off each time you click the button. Something like this example
Public Class Form1
Dim button1_clicked As Boolean = False
Dim button2_clicked As Boolean = False
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If button1_clicked = False Then
button1_clicked = True
TextBox1.Text += "Button1 is on" & vbCrLf
Else
button1_clicked = False
TextBox1.Text += "Button1 is off" & vbCrLf
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If button2_clicked = False Then
button2_clicked = True
TextBox1.Text += "Button2 is on" & vbCrLf
Else
button2_clicked = False
TextBox1.Text += "Button2 is off" & vbCrLf
End If
End Sub
End Class
Ancient Dragon
Achieved Level 70
32,118 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,575
Skill Endorsements: 69
If you need to record the status of the button click a simple boolean in the click handler routine can handle that.
When you quote the part of the post you're referring it's easier for people to understand.
I think this will do what you want. But you might find it easier to use TnTinMN's suggestion of a checkbox that looks like a button. It has a boolean property that changes whenever it's clicked.
Public Class Form1
Dim ButtonClick() As Boolean = {False, False, False, False, False}
Private Sub Button0_Click(sender As Object, e As EventArgs) Handles Button0.Click
ButtonClick(0) = Not ButtonClick(0)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ButtonClick(1) = Not ButtonClick(1)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ButtonClick(2) = Not ButtonClick(2)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
ButtonClick(3) = Not ButtonClick(3)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
ButtonClick(4) = Not ButtonClick(4)
End Sub
Private Sub Timer1_Tick()
If ButtonClick(0) And ButtonClick(2) Then
Button3.Show
Else
If ButtonClick(0) And ButtonClick(3) Then
Button4.Show
End If
End If
End Sub
End Class
tinstaafl
Nearly a Posting Virtuoso
1,312 posts since Jun 2010
Reputation Points: 341
Solved Threads: 227
Skill Endorsements: 14
This solved a simular problem for me is a different appraoch but it does what you want it to do
Public Class Form1
Dim ButClicked As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click, Button3.Click, Button4.Click
Dim strName As String = ""
Dim text As Button = sender
strName = text.Name
If strName = "Button1" Then
Button1.Hide()
ButClicked = ButClicked + 1
ElseIf strName = "Button3" Then
ButClicked = ButClicked + 3
ElseIf strName = "Button4" Then
ButClicked = ButClicked + 4
End If
End Sub
Private Sub Timer1_Tick_1(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
If ButClicked = 4 Then
Button2.Show()
ButClicked = 0
ElseIf ButClicked = 5 Then
Button5.Show()
ButClicked = 0
End If
End Sub
End Class
Gé48
Junior Poster in Training
63 posts since Apr 2010
Reputation Points: 11
Solved Threads: 10
Skill Endorsements: 0
If you use the Visible or the Enabled property you can do it without the timer.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button3.Click, Button4.Click
Dim TempButton As Button = sender
TempButton.Visible = False
If Not Button1.Visible And Not Button3.Visible Then
Button2.Visible = True
ElseIf Not Button1.Visible And Not Button4.Visible Then
Button5.Visible = True
End If
End Sub
tinstaafl
Nearly a Posting Virtuoso
1,312 posts since Jun 2010
Reputation Points: 341
Solved Threads: 227
Skill Endorsements: 14